Struct Wtf8
#[repr(transparent)]
pub struct Wtf8 { pub(in ::wtf8) bytes: [u8] }
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
impl Wtf8
fn is_code_point_boundary(&self, index: usize) -> boolCopied from str::is_char_boundary
fn check_utf8_boundary(&self, index: usize)Verify that
indexis 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.fn try_check_utf8_boundary(&self, index: usize) -> Result<(), Utf8BoundaryError>
impl Wtf8
fn from_str(value: &str) -> &Wtf8Creates a WTF-8 slice from a UTF-8
&strslice.unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8Creates a WTF-8 slice from a WTF-8 byte slice.
Safety
valuemust contain well-formed WTF-8.unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8Creates a mutable WTF-8 slice from a mutable WTF-8 byte slice.
Safety
valuemust contain well-formed WTF-8.fn len(&self) -> usizeReturns the length, in WTF-8 bytes.
fn is_empty(&self) -> boolfn ascii_byte_at(&self, position: usize) -> u8Returns the code point at
positionif it is in the ASCII range, orb'\xFF'otherwise.Panics
Panics if
positionis beyond the end of the string.fn code_points(&self) -> Wtf8CodePoints<'_>Returns an iterator for the string’s code points.
fn as_bytes(&self) -> &[u8]Access raw bytes of WTF-8 data
fn as_str(&self) -> Result<&str, Utf8Error>Tries to convert the string to UTF-8 and return a
&strslice.Returns
Noneif the string contains surrogates.This does not copy the data.
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_utf16on 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>fn make_ascii_lowercase(&mut self)fn make_ascii_uppercase(&mut self)fn is_ascii(&self) -> boolfn eq_ignore_ascii_case(&self, other: &Self) -> bool
Trait Implementations
impl AsRef<[u8]> for Wtf8
fn as_ref(&self) -> &[u8]
impl CloneToUninit for Wtf8
unsafe fn clone_to_uninit(&self, dst: *mut u8)
impl Debug for Wtf8
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
impl Display for Wtf8
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
impl Eq for Wtf8
fn assert_fields_are_eq(&self)
impl Hash for Wtf8
fn hash<H: Hasher>(&self, state: &mut H)
impl Index<Range<usize>> for Wtf8
type Output = Wtf8;fn index(&self, range: Range<usize>) -> &Wtf8
impl Index<RangeFrom<usize>> for Wtf8
type Output = Wtf8;fn index(&self, range: RangeFrom<usize>) -> &Wtf8
impl Index<RangeFull> for Wtf8
type Output = Wtf8;fn index(&self, _range: RangeFull) -> &Wtf8
impl Index<RangeTo<usize>> for Wtf8
type Output = Wtf8;fn index(&self, range: RangeTo<usize>) -> &Wtf8
impl Ord for Wtf8
fn cmp(&self, other: &Wtf8) -> Ordering
impl PartialEq for Wtf8
fn eq(&self, other: &Wtf8) -> bool
impl PartialOrd for Wtf8
fn partial_cmp(&self, other: &Wtf8) -> Option<Ordering>