Struct CharIndices
pub struct CharIndices<'a> { /* private fields */ }
An iterator over Unicode scalar values in a byte string and their byte index positions.
When invalid UTF-8 byte sequences are found, they are substituted with the
Unicode replacement codepoint (U+FFFD) using the
"maximal subpart" strategy.
Note that this is slightly different from the CharIndices iterator
provided by the standard library. Aside from working on possibly invalid
UTF-8, this iterator provides both the corresponding starting and ending
byte indices of each codepoint yielded. The ending position is necessary to
slice the original byte string when invalid UTF-8 bytes are converted into
a Unicode replacement codepoint, since a single replacement codepoint can
substitute anywhere from 1 to 3 invalid bytes (inclusive).
This iterator is created by the
char_indices method provided
by the ByteSlice extension trait for &[u8].
Implementations
impl<'a> CharIndices<'a>
fn as_bytes(&self) -> &'a [u8]View the underlying data as a subslice of the original data.
The slice returned has the same lifetime as the original slice, and so the iterator can continue to be used while this exists.
Examples
use ByteSlice; let mut it = b"abc".char_indices; assert_eq!; it.next; assert_eq!; it.next; it.next; assert_eq!;
Trait Implementations
impl<'a> Clone for CharIndices<'a>
fn clone(&self) -> CharIndices<'a>
impl<'a> Debug for CharIndices<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<'a> DoubleEndedIterator for CharIndices<'a>
fn next_back(&mut self) -> Option<(usize, usize, char)>
impl<'a> FusedIterator for CharIndices<'a>
impl<'a> Iterator for CharIndices<'a>
type Item = (usize, usize, char);fn next(&mut self) -> Option<(usize, usize, char)>
Auto Trait Implementations
impl<'a> Freeze for CharIndices<'a>
impl<'a> RefUnwindSafe for CharIndices<'a>
impl<'a> Send for CharIndices<'a>
impl<'a> Sync for CharIndices<'a>
impl<'a> Unpin for CharIndices<'a>
impl<'a> UnsafeUnpin for CharIndices<'a>
impl<'a> UnwindSafe for CharIndices<'a>
Blanket Implementations
impl<I> IntoIterator for CharIndices<'a>
where
I: Iterator,
type Item = <I as Iterator>::Item;type IntoIter = I;fn into_iter(self) -> I
impl<T> Any for CharIndices<'a>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for CharIndices<'a>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for CharIndices<'a>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for CharIndices<'a>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for CharIndices<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for CharIndices<'a>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for CharIndices<'a>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for CharIndices<'a>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for CharIndices<'a>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>