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

source

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.

source

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.

source

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.

source

pub fn len(&self) -> usize

Returns the length, in WTF-8 bytes.

source

pub fn is_empty(&self) -> bool

source

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.

source

pub fn code_points(&self) -> Wtf8CodePoints<'_>

Returns an iterator for the string’s code points.

source

pub fn as_bytes(&self) -> &[u8]

Access raw bytes of WTF-8 data

source

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.

source

pub fn to_owned(&self) -> Wtf8Buf

Creates an owned Wtf8Buf from a borrowed Wtf8.

source

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).

source

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.

source

fn next_surrogate(&self, pos: usize) -> Option<(usize, u16)>

source

fn final_lead_surrogate(&self) -> Option<u16>

source

fn initial_trail_surrogate(&self) -> Option<u16>

source

pub fn clone_into(&self, buf: &mut Wtf8Buf)

source

pub fn into_box(&self) -> Box<Wtf8>

Boxes this Wtf8.

source

pub fn empty_box() -> Box<Wtf8>

Creates a boxed, empty Wtf8.

source

pub fn into_arc(&self) -> Arc<Wtf8>

source

pub fn into_rc(&self) -> Rc<Wtf8>

source

pub fn make_ascii_lowercase(&mut self)

source

pub fn make_ascii_uppercase(&mut self)

source

pub fn to_ascii_lowercase(&self) -> Wtf8Buf

source

pub fn to_ascii_uppercase(&self) -> Wtf8Buf

source

pub fn is_ascii(&self) -> bool

source

pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool

Trait Implementations§

source§

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§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Wtf8

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Eq for Wtf8

source§

impl Hash for Wtf8

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
source§

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.

§

type Output = Wtf8

The returned type after indexing.
source§

fn index(&self, range: Range<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
source§

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.

§

type Output = Wtf8

The returned type after indexing.
source§

fn index(&self, range: RangeFrom<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeFull> for Wtf8

§

type Output = Wtf8

The returned type after indexing.
source§

fn index(&self, _range: RangeFull) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
source§

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.

§

type Output = Wtf8

The returned type after indexing.
source§

fn index(&self, range: RangeTo<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
source§

impl Ord for Wtf8

source§

fn cmp(&self, other: &Wtf8) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl PartialEq<Wtf8> for Wtf8

source§

fn eq(&self, other: &Wtf8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Wtf8> for Wtf8

source§

fn partial_cmp(&self, other: &Wtf8) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StructuralEq for Wtf8

source§

impl StructuralPartialEq for Wtf8

Auto Trait Implementations§

§

impl RefUnwindSafe for Wtf8

§

impl Send for Wtf8

§

impl !Sized for Wtf8

§

impl Sync for Wtf8

§

impl Unpin for Wtf8

§

impl UnwindSafe for Wtf8

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more