Wtf8Buf

Struct Wtf8Buf 

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

A WTF-8 dynamically sized, growable string.

Implementations§

Source§

impl Wtf8Buf

Source

pub const fn new() -> Wtf8Buf

Creates a new, empty WTF-8 string.

Source

pub fn with_capacity(capacity: usize) -> Wtf8Buf

Creates a new, empty WTF-8 string with pre-allocated capacity for capacity bytes.

Source

pub fn from_string(string: String) -> Wtf8Buf

Creates a WTF-8 string from a UTF-8 String.

This takes ownership of the String and does not copy.

Since WTF-8 is a superset of UTF-8, this always succeeds.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more bytes to be inserted in the given Wtf8Buf. The collection may reserve more space to avoid frequent reallocations.

§Panics

Panics if the new capacity overflows usize.

Source

pub fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for exactly additional more elements to be inserted in the given Wtf8Buf. After calling reserve_exact, capacity will be greater than or equal to self.len() + additional. Does nothing if the capacity is already sufficient.

Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.

§Panics

Panics if the new capacity overflows usize.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.

Source

pub fn capacity(&self) -> usize

Returns the number of bytes that this string buffer can hold without reallocating.

Source

pub fn from_str(str: &str) -> Wtf8Buf

Creates a WTF-8 string from a UTF-8 &str slice.

This copies the content of the slice.

Since WTF-8 is a superset of UTF-8, this always succeeds.

Source

pub fn clear(&mut self)

Clears the string.

Source

pub fn from_utf16<I>(v: I) -> Wtf8Buf
where I: IntoIterator<Item = u16>,

Creates a WTF-8 string from a potentially ill-formed UTF-16 iterator of 16-bit code units.

This is lossless: calling .encode_utf16() on the resulting string will always return the original code units.

Source

pub fn as_wtf8(&self) -> &Wtf8

Returns the slice of this object.

Source

pub fn as_mut_wtf8(&mut self) -> &mut Wtf8

Returns the slice of this object.

Source

pub fn push_str(&mut self, other: &str)

Append a UTF-8 slice at the end of the string.

Source

pub fn push_wtf8(&mut self, other: &Wtf8)

Append a string with WTF-8 encoding.

This replaces newly paired surrogates at the boundary with a supplementary code point, like concatenating ill-formed UTF-16 strings effectively would.

Source

pub fn push_char(&mut self, c: char)

Append a Unicode scalar value at the end of the string.

Source

pub fn push(&mut self, code_point: CodePoint)

Append a code point at the end of the string.

This replaces newly paired surrogates at the boundary with a supplementary code point, like concatenating ill-formed UTF-16 strings effectively would.

Source

pub fn truncate(&mut self, new_len: usize)

Shortens a string to the specified length.

§Panics

Panics if new_len > current length, or if new_len is not a code point boundary.

Source

pub fn into_string(self) -> Result<String, IntoStringError>

Consumes the WTF-8 string and tries to convert it to UTF-8.

This does not copy the data.

If the contents are not well-formed UTF-8 (that is, if the string contains surrogates), the original WTF-8 string is returned instead.

Source

pub fn into_string_lossy(self) -> String

Consumes the WTF-8 string and converts it lossily to UTF-8.

This does not copy the data (but may overwrite parts of it in place).

Surrogates are replaced with "\u{FFFD}" (the replacement character “�”)

Source

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

Converts this Wtf8Buf into a boxed Wtf8.

Source

pub fn from_box(boxed: Box<Wtf8>) -> Wtf8Buf

Converts a Box<Wtf8> into a Wtf8Buf.

Methods from Deref<Target = Wtf8>§

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 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 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 Clone for Wtf8Buf

Source§

fn clone(&self) -> Wtf8Buf

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Wtf8Buf

Source§

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

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

impl Deref for Wtf8Buf

Source§

type Target = Wtf8

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Wtf8

Dereferences the value.
Source§

impl DerefMut for Wtf8Buf

Source§

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

Mutably dereferences the value.
Source§

impl Display for Wtf8Buf

Source§

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

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

impl<'a> Extend<&'a CodePoint> for Wtf8Buf

Source§

fn extend<T: IntoIterator<Item = &'a CodePoint>>(&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<'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<'a> Extend<&'a char> for Wtf8Buf

Source§

fn extend<T: IntoIterator<Item = &'a char>>(&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<'a> Extend<&'a str> for Wtf8Buf

Source§

fn extend<T: IntoIterator<Item = &'a str>>(&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 Extend<CodePoint> for Wtf8Buf

Append code points from an iterator to the string.

This replaces surrogate code point pairs with supplementary code points, like concatenating ill-formed UTF-16 strings effectively would.

Source§

fn extend<T: IntoIterator<Item = CodePoint>>(&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 Extend<char> for Wtf8Buf

Source§

fn extend<T: IntoIterator<Item = char>>(&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 Wtf8Buf

Source§

fn from(x: &Wtf8) -> Wtf8Buf

Converts to this type from the input type.
Source§

impl From<&str> for Wtf8Buf

Source§

fn from(x: &str) -> Wtf8Buf

Converts to this type from the input type.
Source§

impl From<String> for Wtf8Buf

Source§

fn from(x: String) -> Wtf8Buf

Converts to this type from the input type.
Source§

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

Source§

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

Creates a value from an iterator. Read more
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<'a> FromIterator<&'a char> for Wtf8Buf

Source§

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

Creates a value from an iterator. Read more
Source§

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

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<CodePoint> for Wtf8Buf

Creates a new WTF-8 string from an iterator of code points.

This replaces surrogate code point pairs with supplementary code points, like concatenating ill-formed UTF-16 strings effectively would.

Source§

fn from_iter<T: IntoIterator<Item = CodePoint>>(iter: T) -> Wtf8Buf

Creates a value from an iterator. Read more
Source§

impl FromIterator<char> for Wtf8Buf

Source§

fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Wtf8Buf

Creates a value from an iterator. Read more
Source§

impl FromStr for Wtf8Buf

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Infallible>

Parses a string s to return a value of this type. Read more
Source§

impl Ord for Wtf8Buf

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Wtf8Buf

Source§

fn eq(&self, other: &Wtf8Buf) -> 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 Wtf8Buf

Source§

fn partial_cmp(&self, other: &Wtf8Buf) -> 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 Eq for Wtf8Buf

Source§

impl StructuralPartialEq for Wtf8Buf

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.