Struct wtf8_rs::Wtf8Buf[][src]

pub struct Wtf8Buf { /* fields omitted */ }

A WTF-8 dynamically sized, growable string.

Implementations

impl Wtf8Buf[src]

pub const fn new() -> Wtf8Buf[src]

Creates a new, empty WTF-8 string.

pub fn with_capacity(capacity: usize) -> Wtf8Buf[src]

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

pub fn from_string(string: String) -> Wtf8Buf[src]

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.

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

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.

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

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.

pub fn shrink_to_fit(&mut self)[src]

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.

pub fn capacity(&self) -> usize[src]

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

pub fn from_str(str: &str) -> Wtf8Buf[src]

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.

pub fn clear(&mut self)[src]

Clears the string.

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

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.

pub fn as_wtf8(&self) -> &Wtf8[src]

Returns the slice of this object.

pub fn as_mut_wtf8(&mut self) -> &mut Wtf8[src]

Returns the slice of this object.

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

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

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

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.

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

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

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

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.

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

Shortens a string to the specified length.

Panics

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

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

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.

pub fn into_string_lossy(self) -> String[src]

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 “�”)

pub fn into_box(self) -> Box<Wtf8>[src]

Converts this Wtf8Buf into a boxed Wtf8.

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

Converts a Box<Wtf8> into a Wtf8Buf.

Methods from Deref<Target = Wtf8>

pub fn len(&self) -> usize[src]

Returns the length, in WTF-8 bytes.

pub fn is_empty(&self) -> bool[src]

Returns whether this is empty.

pub fn ascii_byte_at(&self, position: usize) -> u8[src]

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.

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

Notable traits for CodePoints<'_>

impl Iterator for CodePoints<'_> type Item = CodePoint;
[src]

Returns an iterator for the string’s code points.

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

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.

pub fn to_string_lossy(&self) -> Cow<'_, str>[src]

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

pub fn get<I: Wtf8Index>(&self, i: I) -> Option<&Self>[src]

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

Returns None whenever index would panic.

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

Notable traits for EncodeUtf16<'_>

impl Iterator for EncodeUtf16<'_> type Item = u16;
[src]

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

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

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

Safety

Produces undefined behaviour whenever index would panic.

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

Whether a given index is at a code point boundary.

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

Boxes this Wtf8.

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

Boxes this Wtf8 with Arc.

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

Boxes this Wtf8 with Rc.

pub fn make_ascii_lowercase(&mut self)[src]

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.

pub fn make_ascii_uppercase(&mut self)[src]

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.

pub fn to_ascii_lowercase(&self) -> Wtf8Buf[src]

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.

pub fn to_ascii_uppercase(&self) -> Wtf8Buf[src]

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.

pub fn is_ascii(&self) -> bool[src]

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

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

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

impl AsMut<Wtf8> for Wtf8Buf[src]

impl AsRef<Wtf8> for Wtf8Buf[src]

impl Borrow<Wtf8> for Wtf8Buf[src]

impl BorrowMut<Wtf8> for Wtf8Buf[src]

impl Clone for Wtf8Buf[src]

impl Debug for Wtf8Buf[src]

impl Deref for Wtf8Buf[src]

type Target = Wtf8

The resulting type after dereferencing.

impl DerefMut for Wtf8Buf[src]

impl Display for Wtf8Buf[src]

impl Eq for Wtf8Buf[src]

impl<'a> Extend<&'a CodePoint> for Wtf8Buf[src]

impl<'a> Extend<&'a Wtf8> for Wtf8Buf[src]

impl<'a> Extend<&'a char> for Wtf8Buf[src]

impl<'a> Extend<&'a str> for Wtf8Buf[src]

impl Extend<CodePoint> for Wtf8Buf[src]

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.

impl Extend<char> for Wtf8Buf[src]

impl From<&'_ Wtf8> for Wtf8Buf[src]

impl From<&'_ str> for Wtf8Buf[src]

impl From<String> for Wtf8Buf[src]

impl<'a> FromIterator<&'a CodePoint> for Wtf8Buf[src]

impl<'a> FromIterator<&'a Wtf8> for Wtf8Buf[src]

impl<'a> FromIterator<&'a char> for Wtf8Buf[src]

impl<'a> FromIterator<&'a str> for Wtf8Buf[src]

impl FromIterator<CodePoint> for Wtf8Buf[src]

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.

impl FromIterator<char> for Wtf8Buf[src]

impl FromStr for Wtf8Buf[src]

type Err = Infallible

The associated error which can be returned from parsing.

impl Ord for Wtf8Buf[src]

impl PartialEq<Wtf8Buf> for Wtf8Buf[src]

impl PartialOrd<Wtf8Buf> for Wtf8Buf[src]

impl StructuralEq for Wtf8Buf[src]

impl StructuralPartialEq for Wtf8Buf[src]

Auto Trait Implementations

impl Send for Wtf8Buf

impl Sync for Wtf8Buf

impl Unpin for Wtf8Buf

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.