Wtf8

Struct Wtf8 

Source
pub struct Wtf8 { /* private fields */ }
Expand description

A WTF-8 slice.

Implementations§

Source§

impl Wtf8

Source

pub fn new<T: ?Sized + AsRef<Wtf8>>(x: &T) -> &Self

Coerces into a Wtf8. This accepts an &str argument.

Source

pub fn len(&self) -> usize

Returns the length, in WTF-8 bytes.

Source

pub fn is_empty(&self) -> bool

Returns whether this is empty.

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) -> CodePoints<'_>

Returns an iterator for the string’s code points.

Source

pub fn to_str(&self) -> Result<&str, ToStrError>

Tries to convert the string to UTF-8 and return a &str slice.

Returns Err(_) if the string contains surrogates.

This does not copy the data.

Source

pub fn chunks(&self) -> Chunks<'_>

Converts this string into a iterator of Wtf8Chunk.

The resulting iterator will intercalate Utf8 chunks with one or more UnpairedSurrogate and all contained codepoints can be recovered from it.

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 get<I: Wtf8Index>(&self, i: I) -> Option<&Self>

Returns a slice of the given string for the byte range.

Returns None whenever index would panic.

Source

pub fn encode_utf16(&self) -> EncodeUtf16<'_>

Converts the WTF-8 string to potentially ill-formed UTF-16 and return an iterator of 16-bit code units.

Source

pub unsafe fn get_unchecked<I: Wtf8Index>(&self, i: I) -> &Self

Returns a slice of the given string for the byte range.

§Safety

Produces undefined behaviour whenever index would panic.

Source

pub fn is_code_point_boundary(&self, index: usize) -> bool

Whether a given index is at a code point boundary.

Source

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

Boxes this Wtf8.

Source

pub fn empty_box() -> Box<Wtf8>

Creates a boxed, empty Wtf8.

Source

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

Boxes this Wtf8 with Arc.

Source

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

Boxes this Wtf8 with Rc.

Source

pub fn make_ascii_lowercase(&mut self)

Converts this slice to its ASCII lower case equivalent in-place.

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.

To return a new lowercased value without modifying the existing one, use to_ascii_lowercase.

Source

pub fn make_ascii_uppercase(&mut self)

Converts this slice to its ASCII upper case equivalent in-place.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.

To return a new uppercased value without modifying the existing one, use to_ascii_uppercase.

Source

pub fn to_ascii_lowercase(&self) -> Wtf8Buf

Returns a Wtf8Buf containing a copy of this slice where each byte is mapped to its ASCII lower case equivalent.

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.

Source

pub fn to_ascii_uppercase(&self) -> Wtf8Buf

Returns a Wtf8Buf containing a copy of this slice where each byte is mapped to its ASCII upper case equivalent.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.

To uppercase the value in-place, use make_ascii_uppercase.

Source

pub fn is_ascii(&self) -> bool

Checks if all bytes in this slice are within the ASCII range.

Source

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

Checks that two slices are an ASCII case-insensitive match.

Same as to_ascii_lowercase(a) == to_ascii_lowercase(b), but without allocating and copying temporaries.

Trait Implementations§

Source§

impl AsMut<Wtf8> for Wtf8Buf

Source§

fn as_mut(&mut self) -> &mut Wtf8

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Wtf8> for Wtf8Buf

Source§

fn as_ref(&self) -> &Wtf8

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Wtf8> for str

Source§

fn as_ref(&self) -> &Wtf8

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<Wtf8> for Wtf8Buf

Source§

fn borrow(&self) -> &Wtf8

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<Wtf8> for Wtf8Buf

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Debug for Wtf8

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<'a> Extend<&'a Wtf8> for Wtf8Buf

Source§

fn extend<T: IntoIterator<Item = &'a Wtf8>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<&Wtf8> for Arc<Wtf8>

Source§

fn from(x: &Wtf8) -> Self

Converts to this type from the input type.
Source§

impl From<&Wtf8> for Box<Wtf8>

Source§

fn from(x: &Wtf8) -> Self

Converts to this type from the input type.
Source§

impl From<&Wtf8> for Rc<Wtf8>

Source§

fn from(x: &Wtf8) -> Self

Converts to this type from the input type.
Source§

impl From<&Wtf8> for Wtf8Buf

Source§

fn from(x: &Wtf8) -> Wtf8Buf

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf

Source§

fn from_iter<T: IntoIterator<Item = &'a Wtf8>>(iter: T) -> Wtf8Buf

Creates a value from an iterator. Read more
Source§

impl<T: Wtf8Index> Index<T> for Wtf8

Returns a slice of the given string for the byte range.

§Panics

Panics when the boundaries of the range do not point to code point boundaries, or point beyond the end of the string.

Source§

type Output = Wtf8

The returned type after indexing.
Source§

fn index(&self, index: T) -> &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 for Wtf8

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToOwned for Wtf8

Source§

type Owned = Wtf8Buf

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Wtf8Buf

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Eq for Wtf8

Source§

impl StructuralPartialEq for Wtf8

Auto Trait Implementations§

§

impl Freeze for Wtf8

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more