Struct Wtf8

pub struct Wtf8 { /* private fields */ }
Available on crate features __ecma and ecma_ast only.
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.

Implementations§

§

impl Wtf8

pub const fn from_str(value: &str) -> &Wtf8

Create a WTF-8 slice from a UTF-8 &str slice.

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

pub const fn len(&self) -> usize

Return the length, in WTF-8 bytes.

pub const fn is_empty(&self) -> bool

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

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.

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.

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.

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.

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

Return an iterator for the string’s code points.

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.

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

Return the underlying WTF-8 bytes.

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

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.

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

Create a WTF-8 from a WTF-8 encoded byte slice.

§Safety

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

This means that:

  • All bytes must form valid UTF-8 sequences OR valid surrogate code point encodings
  • Surrogate code points may appear unpaired and be encoded separately, but if they are paired, it should be encoded as a single 4-byte UTF-8 sequence. For example, the byte sequence [0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80] is not valid WTF-8 because WTF-8 forbids encoding a surrogate pair as two separate 3-byte sequences.

Trait Implementations§

§

impl AsRef<Wtf8> for Wtf8Atom

§

fn as_ref(&self) -> &Wtf8

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

impl Borrow<Wtf8> for Wtf8Buf

§

fn borrow(&self) -> &Wtf8

Immutably borrows from an owned value. Read more
§

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]

§

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

Formats the value using the given formatter. Read more
§

impl From<&Wtf8> for Wtf8Atom

§

fn from(s: &Wtf8) -> Wtf8Atom

Converts to this type from the input type.
§

impl<'a> From<&'a str> for &'a Wtf8

§

fn from(s: &'a str) -> &'a Wtf8

Converts to this type from the input type.
§

impl Hash for Wtf8

§

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

Feeds this value into the given Hasher. Read more
§

impl Ord for Wtf8

§

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

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

impl PartialEq<&Wtf8> for Wtf8Atom

§

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

impl PartialEq<&Wtf8> for Wtf8Buf

§

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

impl PartialEq<Wtf8> for Wtf8Atom

§

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

impl PartialEq<Wtf8Atom> for Wtf8

§

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

impl PartialEq<Wtf8Buf> for &Wtf8

§

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

impl PartialEq for Wtf8

§

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

impl PartialOrd for Wtf8

§

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

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

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

Tests less than (for self and other) and is used by the < operator. Read more
§

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

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

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

Tests greater than (for self and other) and is used by the > operator. Read more
§

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

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

impl ToOwned for Wtf8

§

type Owned = Wtf8Buf

The resulting type after obtaining ownership.
§

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
§

impl Eq 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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

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
§

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

§

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

Compare self to key and return true if they are equal.
§

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
§

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

§

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

Compare self to key and return true if they are equal.
§

impl<T, H> Hashable<H> for T
where T: Hash + ?Sized, H: HashOne,

§

fn hash(&self, seed: u64) -> u64

§

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

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.