#[repr(transparent)]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 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 <
.