EncodedStr

Trait EncodedStr 

Source
pub trait EncodedStr: Sealed {
    type CHAR;
    type SLICE: ?Sized;

    const ELEMENT_LEN_BYTE: usize = _;
    const CHAR: usize = Self::ELEMENT_LEN_BYTE;
    const UTF8: bool = false;

    // Required methods
    fn is_ascii(&self) -> bool;
    fn as_bytes(&self) -> &[u8] ;
    unsafe fn get_unchecked<I: SliceIndex<Self::SLICE, Output = Self::SLICE>>(
        &self,
        i: I,
    ) -> &Self;
    unsafe fn get_unchecked_from(&self, range: RangeFrom<usize>) -> &Self;
    fn char_index_strs(&self) -> impl Iterator<Item = (usize, char, &Self)>;
    fn char_len_next_strs(&self) -> impl Iterator<Item = (char, usize, &Self)>;

    // Provided method
    fn chars_count(&self) -> usize { ... }
}
Expand description

§Performance

Although multiple encodings are supported, UTF-8 (str) is most optimized.

TODO: Extended ASCII code pages TODO: Index/SliceIndex

Provided Associated Constants§

Source

const ELEMENT_LEN_BYTE: usize = _

Source

const CHAR: usize = Self::ELEMENT_LEN_BYTE

Source

const UTF8: bool = false

Required Associated Types§

Required Methods§

Source

fn is_ascii(&self) -> bool

Source

fn as_bytes(&self) -> &[u8]

Source

unsafe fn get_unchecked<I: SliceIndex<Self::SLICE, Output = Self::SLICE>>( &self, i: I, ) -> &Self

Source

unsafe fn get_unchecked_from(&self, range: RangeFrom<usize>) -> &Self

Source

fn char_index_strs(&self) -> impl Iterator<Item = (usize, char, &Self)>

Source

fn char_len_next_strs(&self) -> impl Iterator<Item = (char, usize, &Self)>

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EncodedStr for str

Source§

const UTF8: bool = true

Source§

type CHAR = u8

Source§

type SLICE = str

Source§

fn is_ascii(&self) -> bool

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn get_unchecked<I: SliceIndex<Self::SLICE, Output = Self::SLICE>>( &self, i: I, ) -> &Self

Source§

unsafe fn get_unchecked_from(&self, range: RangeFrom<usize>) -> &Self

Source§

fn char_index_strs(&self) -> impl Iterator<Item = (usize, char, &Self)>

Source§

fn char_len_next_strs(&self) -> impl Iterator<Item = (char, usize, &Self)>

Source§

fn chars_count(&self) -> usize

Source§

impl EncodedStr for U16Str

Available on crate feature encoding only.
Source§

type CHAR = u16

Source§

type SLICE = [u16]

Source§

fn is_ascii(&self) -> bool

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn get_unchecked<I: SliceIndex<Self::SLICE, Output = Self::SLICE>>( &self, i: I, ) -> &Self

Source§

unsafe fn get_unchecked_from(&self, range: RangeFrom<usize>) -> &Self

Source§

fn char_index_strs(&self) -> impl Iterator<Item = (usize, char, &Self)>

Source§

fn char_len_next_strs(&self) -> impl Iterator<Item = (char, usize, &Self)>

Source§

impl EncodedStr for U32Str

Available on crate feature encoding only.
Source§

type CHAR = u32

Source§

type SLICE = [u32]

Source§

fn is_ascii(&self) -> bool

Source§

fn as_bytes(&self) -> &[u8]

Source§

unsafe fn get_unchecked<I: SliceIndex<Self::SLICE, Output = Self::SLICE>>( &self, i: I, ) -> &Self

Source§

unsafe fn get_unchecked_from(&self, range: RangeFrom<usize>) -> &Self

Source§

fn char_index_strs(&self) -> impl Iterator<Item = (usize, char, &Self)>

Source§

fn char_len_next_strs(&self) -> impl Iterator<Item = (char, usize, &Self)>

Implementors§