#[repr(transparent)]#[doc(hidden)] pub struct Wtf8 {
bytes: [u8],
}wtf8_internals)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]wtf8_internals)Implementations§
Source§impl Wtf8
impl Wtf8
Sourcepub fn from_str(value: &str) -> &Wtf8
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn from_str(value: &str) -> &Wtf8
wtf8_internals)Creates a WTF-8 slice from a UTF-8 &str slice.
Sourcepub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
🔬This is a nightly-only experimental API. (wtf8_internals)
pub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8
wtf8_internals)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.
Sourcepub unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8
🔬This is a nightly-only experimental API. (wtf8_internals)
pub unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8
wtf8_internals)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.
Sourcepub fn len(&self) -> usize
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn len(&self) -> usize
wtf8_internals)Returns the length, in WTF-8 bytes.
pub fn is_empty(&self) -> bool
wtf8_internals)Sourcepub fn ascii_byte_at(&self, position: usize) -> u8
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn ascii_byte_at(&self, position: usize) -> u8
wtf8_internals)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<'_> ⓘ
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn code_points(&self) -> Wtf8CodePoints<'_> ⓘ
wtf8_internals)Returns an iterator for the string’s code points.
Sourcepub fn as_bytes(&self) -> &[u8]
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn as_bytes(&self) -> &[u8]
wtf8_internals)Access raw bytes of WTF-8 data
Sourcepub fn as_str(&self) -> Result<&str, Utf8Error>
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn as_str(&self) -> Result<&str, Utf8Error>
wtf8_internals)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 encode_wide(&self) -> EncodeWide<'_> ⓘ
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn encode_wide(&self) -> EncodeWide<'_> ⓘ
wtf8_internals)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.
pub fn next_surrogate(&self, pos: usize) -> Option<(usize, u16)>
wtf8_internals)pub fn final_lead_surrogate(&self) -> Option<u16>
wtf8_internals)pub fn initial_trail_surrogate(&self) -> Option<u16>
wtf8_internals)pub fn make_ascii_lowercase(&mut self)
wtf8_internals)pub fn make_ascii_uppercase(&mut self)
wtf8_internals)pub fn is_ascii(&self) -> bool
wtf8_internals)pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
wtf8_internals)Source§impl Wtf8
impl Wtf8
Sourcepub fn is_code_point_boundary(&self, index: usize) -> bool
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn is_code_point_boundary(&self, index: usize) -> bool
wtf8_internals)Copied from str::is_char_boundary
Sourcepub fn check_utf8_boundary(&self, index: usize)
🔬This is a nightly-only experimental API. (wtf8_internals)
pub fn check_utf8_boundary(&self, index: usize)
wtf8_internals)Verify that index is at the edge of either a valid UTF-8 codepoint
(i.e. a codepoint that’s not a surrogate) or of the whole string.
These are the cases currently permitted by OsStr::self_encoded_bytes.
Splitting between surrogates is valid as far as WTF-8 is concerned, but
we do not permit it in the public API because WTF-8 is considered an
implementation detail.
Trait Implementations§
Source§impl CloneToUninit for Wtf8
impl CloneToUninit for Wtf8
Source§impl Debug for Wtf8
Formats the string in double quotes, with characters escaped according to
char::escape_debug and unpaired surrogates represented as \u{xxxx},
where each x is a hexadecimal digit.
impl Debug for Wtf8
Formats the string in double quotes, with characters escaped according to
char::escape_debug and unpaired surrogates represented as \u{xxxx},
where each x is a hexadecimal digit.
Source§impl Display for Wtf8
Formats the string with unpaired surrogates substituted with the replacement
character, U+FFFD.
impl Display for Wtf8
Formats the string with unpaired surrogates substituted with the replacement character, U+FFFD.
Source§impl Index<Range<usize>> for Wtf8
Returns a slice of the given string for the byte range [begin..end).
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
Returns a slice of the given string from byte begin to its end.
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
Returns a slice of the given string from its beginning to byte end.
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 PartialOrd for Wtf8
impl PartialOrd for Wtf8
Source§#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_lt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods)self == other, returns ControlFlow::Continue(()).
Otherwise, returns ControlFlow::Break(self < other). Read moreSource§#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods)__chaining_lt, but for <= instead of <.Source§#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods)__chaining_lt, but for > instead of <.Source§#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
#[doc(hidden)] fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool>
partial_ord_chaining_methods)__chaining_lt, but for >= instead of <.