Struct std::sys_common::wtf8::Wtf8
source · pub struct Wtf8 {
bytes: [u8],
}
Expand description
A borrowed slice of well-formed WTF-8 data.
Similar to &str
, but can additionally contain surrogate code points
if they’re not in a surrogate pair.
Fields§
§bytes: [u8]
Implementations§
source§impl Wtf8
impl Wtf8
sourcepub fn from_str(value: &str) -> &Wtf8
pub fn from_str(value: &str) -> &Wtf8
Creates a WTF-8 slice from a UTF-8 &str
slice.
Since WTF-8 is a superset of UTF-8, this always succeeds.
sourcepub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
pub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
Creates a WTF-8 slice from a WTF-8 byte slice.
Since the byte slice is not checked for valid WTF-8, this functions is marked unsafe.
sourceunsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8
unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8
Creates a mutable WTF-8 slice from a mutable WTF-8 byte slice.
Since the byte slice is not checked for valid WTF-8, this functions is marked unsafe.
pub fn is_empty(&self) -> bool
sourcepub fn ascii_byte_at(&self, position: usize) -> u8
pub fn ascii_byte_at(&self, position: usize) -> u8
Returns the code point at position
if it is in the ASCII range,
or b'\xFF'
otherwise.
Panics
Panics if position
is beyond the end of the string.
sourcepub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
pub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
Returns an iterator for the string’s code points.
sourcepub fn as_str(&self) -> Result<&str, Utf8Error>
pub fn as_str(&self) -> Result<&str, Utf8Error>
Tries to convert the string to UTF-8 and return a &str
slice.
Returns None
if the string contains surrogates.
This does not copy the data.
sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Lossily converts the string to UTF-8.
Returns a UTF-8 &str
slice if the contents are well-formed in UTF-8.
Surrogates are replaced with "\u{FFFD}"
(the replacement character “�”).
This only copies the data if necessary (if it contains any surrogate).
sourcepub fn encode_wide(&self) -> EncodeWide<'_> ⓘ
pub fn encode_wide(&self) -> EncodeWide<'_> ⓘ
Converts the WTF-8 string to potentially ill-formed UTF-16 and return an iterator of 16-bit code units.
This is lossless:
calling Wtf8Buf::from_ill_formed_utf16
on the resulting code units
would always return the original WTF-8 string.
fn next_surrogate(&self, pos: usize) -> Option<(usize, u16)>
fn final_lead_surrogate(&self) -> Option<u16>
fn initial_trail_surrogate(&self) -> Option<u16>
pub fn clone_into(&self, buf: &mut Wtf8Buf)
pub fn into_arc(&self) -> Arc<Wtf8>
pub fn into_rc(&self) -> Rc<Wtf8>
pub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_uppercase(&mut self)
pub fn to_ascii_lowercase(&self) -> Wtf8Buf
pub fn to_ascii_uppercase(&self) -> Wtf8Buf
pub fn is_ascii(&self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Trait Implementations§
source§impl Debug for Wtf8
impl Debug for Wtf8
Format the slice with double quotes,
and surrogates as \u
followed by four hexadecimal digits.
Example: "a\u{D800}"
for a slice with code points [U+0061, U+D800]
source§impl Index<Range<usize>> for Wtf8
impl Index<Range<usize>> for Wtf8
Returns a slice of the given string for the byte range [begin
..end
).
Panics
Panics when begin
and end
do not point to code point boundaries,
or point beyond the end of the string.
source§impl Index<RangeFrom<usize>> for Wtf8
impl Index<RangeFrom<usize>> for Wtf8
Returns a slice of the given string from byte begin
to its end.
Panics
Panics when begin
is not at a code point boundary,
or is beyond the end of the string.
source§impl Index<RangeTo<usize>> for Wtf8
impl Index<RangeTo<usize>> for Wtf8
Returns a slice of the given string from its beginning to byte end
.
Panics
Panics when end
is not at a code point boundary,
or is beyond the end of the string.
source§impl PartialEq<Wtf8> for Wtf8
impl PartialEq<Wtf8> for Wtf8
source§impl PartialOrd<Wtf8> for Wtf8
impl PartialOrd<Wtf8> for Wtf8
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more