pub struct StrIndex {
pub char_index: usize,
pub byte_index: usize,
}Expand description
Dealing with string indices can be hard, this struct ensures that both the character and byte index are provided for correct indexing.
char_index and byte_index are not guaranteed to agree with each other.
For ascii only text they are always equal, but multi byte characters
make them diverge:
// 'ö' is 1 character but 2 bytes in UTF-8, so the position after
// "Abcöö" is character 5 but byte 7.
assert_eq!(camel_case_until("Abc\u{f6}\u{f6}DD"), StrIndex::new(5, 7));Fields§
§char_index: usizeThe number of characters between the start of the str and this position
byte_index: usizeThe number of bytes between the start of the str and this position
Implementations§
Trait Implementations§
impl Eq for StrIndex
impl StructuralPartialEq for StrIndex
Auto Trait Implementations§
impl DynSend for StrIndex
impl DynSync for StrIndex
impl Freeze for StrIndex
impl RefUnwindSafe for StrIndex
impl Send for StrIndex
impl Sync for StrIndex
impl Unpin for StrIndex
impl UnsafeUnpin for StrIndex
impl UnwindSafe for StrIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes