use super::Utf8Char;
use std::mem::transmute;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct IterUtf8Char<'a> {
bytes: &'a [u8],
}
impl<'a> IterUtf8Char<'a> {
#[inline]
pub const fn new(bytes: &'a str) -> Self {
let bytes = bytes.as_bytes();
Self { bytes }
}
#[inline]
pub const unsafe fn new_from_bytes_unchecked(bytes: &'a [u8]) -> Self {
Self { bytes }
}
}
impl<'a> Iterator for IterUtf8Char<'a> {
type Item = &'a Utf8Char;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let byte = self.bytes.first()?;
let l = unsafe { super::utf8_len_from_first_byte(*byte) };
let c: &Utf8Char = unsafe { transmute(self.bytes.get(0..l)?) };
self.bytes = &self.bytes[l..];
Some(c)
}
}