pub struct MStr { /* private fields */ }Expand description
A Modified UTF-8 string slice, like str.
Implementations§
Source§impl MStr
impl MStr
Sourcepub fn from_mutf8(v: &[u8]) -> Result<&MStr, DecodeError>
pub fn from_mutf8(v: &[u8]) -> Result<&MStr, DecodeError>
Creates a new string from a modified UTF-8 byte slice.
Sourcepub fn from_mutf8_mut(v: &mut [u8]) -> Result<&mut MStr, DecodeError>
pub fn from_mutf8_mut(v: &mut [u8]) -> Result<&mut MStr, DecodeError>
Creates a new string from a modified UTF-8 byte slice.
Sourcepub const unsafe fn from_mutf8_unchecked(v: &[u8]) -> &MStr
pub const unsafe fn from_mutf8_unchecked(v: &[u8]) -> &MStr
Creates a string from a modified UTF-8 byte slice without checking its contents.
§Safety
This slice may not contain bytes that do not make up a modified UTF-8 string.
Sourcepub unsafe fn from_mutf8_unchecked_mut(v: &mut [u8]) -> &mut MStr
pub unsafe fn from_mutf8_unchecked_mut(v: &mut [u8]) -> &mut MStr
Creates a string from a modified UTF-8 byte slice without checking its contents.
§Safety
This slice may not contain bytes that do not make up a modified UTF-8 string.
Sourcepub fn to_str(&self) -> Option<&str>
pub fn to_str(&self) -> Option<&str>
Checks whether the modified UTF-8 string is valid UTF-8 and returns a &str if it is.
Sourcepub fn is_char_boundary(&self, index: usize) -> bool
pub fn is_char_boundary(&self, index: usize) -> bool
Returns whether the index-th byte is the first byte of a modified UTF-8 code point sequence or the end of the string.
Sourcepub fn chars(&self) -> Chars<'_> ⓘ
pub fn chars(&self) -> Chars<'_> ⓘ
Returns an iterator over the chars in this string.
For valid unicode characters, Ok is yielded.
If a character is invalid, then its code will be returned in the Err case.
If you don’t care about invalid characters, use chars_lossy.
Sourcepub fn chars_lossy(&self) -> CharsLossy<'_> ⓘ
pub fn chars_lossy(&self) -> CharsLossy<'_> ⓘ
Returns an iterator over the chars in this string.
Invalid characters are replaced with U+FFFD (char::REPLACEMENT_CHARACTER).
Sourcepub fn display(&self) -> Display<'_>
pub fn display(&self) -> Display<'_>
Provides a value of a type that implements Display.
Invalid characters are displayed as U+FFFD (char::REPLACEMENT_CHARACTER).