Skip to main content

Wtf8Atom

Struct Wtf8Atom 

Source
pub struct Wtf8Atom(/* private fields */);
Expand description

Clone-on-write WTF-8 string.

See [tendril] for more details.

Implementations§

Source§

impl Wtf8Atom

Source

pub fn new<S>(s: S) -> Self
where Wtf8Atom: From<S>,

Creates a new Wtf8Atom from a string.

Source

pub fn as_wtf8(&self) -> &Wtf8

Source

pub fn as_atom(&self) -> Option<&Atom>

Source

pub fn to_atom_lossy(&self) -> Cow<'_, Atom>

Returns the UTF-8 Atom representation, borrowing when possible.

Source

pub fn try_into_atom(self) -> Result<Atom, Wtf8Atom>

Try to convert this to a UTF-8 Atom.

Returns Atom if the string is valid UTF-8, otherwise returns the original Wtf8Atom.

Source

pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self

Creates a new Wtf8Atom from a byte slice.

§Safety

The caller must ensure that bytes is a well-formed WTF-8 byte sequence.

See hstr::wtf8::Wtf8::from_bytes_unchecked for more details.

Methods from Deref<Target = Wtf8>§

Source

pub fn len(&self) -> usize

Return the length, in WTF-8 bytes.

Source

pub fn is_empty(&self) -> bool

Return true if the string has a length of zero bytes.

Source

pub fn is_ascii(&self) -> bool

Return true if the string contains only ASCII characters.

Source

pub fn slice(&self, begin: usize, end: usize) -> &Wtf8

Return a slice of the given string for the byte range [begin..end).

§Failure

Fails when begin and end do not point to code point boundaries, or point beyond the end of the string.

Source

pub fn slice_from(&self, begin: usize) -> &Wtf8

Return a slice of the given string from byte begin to its end.

§Failure

Fails when begin is not at a code point boundary, or is beyond the end of the string.

Source

pub fn slice_to(&self, end: usize) -> &Wtf8

Return a slice of the given string from its beginning to byte end.

§Failure

Fails when end is not at a code point boundary, or is beyond the end of the string.

Source

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

Return the code point at position if it is in the ASCII range, or `b’\xFF’ otherwise.

§Failure

Fails if position is beyond the end of the string.

Source

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

Return an iterator for the string’s code points.

Source

pub fn contains_char(&self, ch: char) -> bool

Returns true if this WTF-8 string contains the given character.

Source

pub fn contains(&self, code_point: CodePoint) -> bool

Returns true if this WTF-8 string contains the given code point.

Source

pub fn starts_with(&self, pattern: &str) -> bool

Returns true if this WTF-8 string starts with the given UTF-8 string.

Source

pub fn as_str(&self) -> Option<&str>

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

Return None if the string contains surrogates.

This does not copy the data.

Source

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

Return the underlying WTF-8 bytes.

Source

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

Lossily convert the string to UTF-8. Return an 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 to_ill_formed_utf16(&self) -> IllFormedUtf16CodeUnits<'_> ⓘ

Convert 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

pub fn to_uppercase(&self) -> Wtf8Buf

Returns the uppercase equivalent of this wtf8 slice, as a new Wtf8Buf.

Source

pub fn to_lowercase(&self) -> Wtf8Buf

Returns the lowercase equivalent of this wtf8 slice, as a new Wtf8Buf.

Trait Implementations§

Source§

impl Borrow<Wtf8Atom> for Atom

Source§

fn borrow(&self) -> &Wtf8Atom

Immutably borrows from an owned value. Read more
Source§

impl Clone for Wtf8Atom

Source§

fn clone(&self) -> Wtf8Atom

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Wtf8Atom

Source§

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

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

impl Default for Wtf8Atom

Source§

fn default() -> Wtf8Atom

Returns the “default value” for a type. Read more
Source§

impl Deref for Wtf8Atom

Source§

type Target = Wtf8

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for Wtf8Atom

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Wtf8Atom

Source§

impl From<&Wtf8Atom> for Wtf8Buf

Source§

fn from(s: &Wtf8Atom) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Wtf8Atom
where Wtf8Atom: From<T>,

Source§

fn from(s: T) -> Self

Converts to this type from the input type.
Source§

impl Hash for Wtf8Atom

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Wtf8Atom

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · 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 Wtf8Atom

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T> PartialEq<T> for Wtf8Atom
where Wtf8Atom: PartialEq<T>, T: ?Sized,

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Wtf8Atom

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Serialize for Wtf8Atom

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Wtf8Atom

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

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

§

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

Checks if this value is equivalent to the given key. 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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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