Wtf8

Struct Wtf8 

Source
pub struct Wtf8 { /* private fields */ }
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§

Source§

impl Wtf8

Source

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

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

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

Source

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

Creates a WTF-8 slice from a WTF-8 byte slice.

Since the byte slice is not checked for valid WTF-8, this functions is marked unsafe.

Source

pub fn len(&self) -> usize

Returns the length, in WTF-8 bytes.

Source

pub fn is_empty(&self) -> bool

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 as_str(&self) -> Option<&str>

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

Returns None if the string contains surrogates.

This does not copy the data.

Source

pub fn encode_wide(&self) -> EncodeWide<'_>

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

impl Wtf8

Source

pub fn make_ascii_uppercase(&mut self)

Trait Implementations§

Source§

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]

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 Hash for Wtf8

Source§

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

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

impl Hay for Wtf8

Source§

type Index = usize

The index type of the haystack. Typically a usize. Read more
Source§

fn empty<'a>() -> &'a Self

Creates an empty hay. Read more
Source§

fn start_index(&self) -> usize

Obtains the index to the start of the hay. Read more
Source§

fn end_index(&self) -> usize

Obtains the index to the end of the hay. Read more
Source§

unsafe fn slice_unchecked(&self, range: Range<usize>) -> &Self

Obtains a child hay by slicing self. Read more
Source§

unsafe fn next_index(&self, index: usize) -> usize

Returns the next immediate index in this haystack. Read more
Source§

unsafe fn prev_index(&self, index: usize) -> usize

Returns the previous immediate index in this haystack. Read more
Source§

impl Index<Range<usize>> for Wtf8

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

§Panics

Panics when begin and end 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, range: Range<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for Wtf8

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

§Panics

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

Source§

type Output = Wtf8

The returned type after indexing.
Source§

fn index(&self, range: RangeFrom<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for Wtf8

Source§

type Output = Wtf8

The returned type after indexing.
Source§

fn index(&self, _range: RangeFull) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for Wtf8

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

§Panics

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

Source§

type Output = Wtf8

The returned type after indexing.
Source§

fn index(&self, range: RangeTo<usize>) -> &Wtf8

Performs the indexing (container[index]) operation. Read more
Source§

impl<'h, 'p> Needle<&'h Wtf8> for &'p str

Source§

type Searcher = SliceSearcher<'p, u8>

The searcher associated with this needle.
Source§

type Consumer = NaiveSearcher<'p, u8>

The consumer associated with this needle.
Source§

fn into_searcher(self) -> Self::Searcher

Produces a searcher for this needle.
Source§

fn into_consumer(self) -> Self::Consumer

Produces a consumer for this needle. Read more
Source§

impl<'p, H: Haystack<Target = Wtf8>> Needle<H> for &'p Wtf8

Source§

type Searcher = Wtf8Searcher<SliceSearcher<'p, u8>>

The searcher associated with this needle.
Source§

type Consumer = Wtf8Searcher<NaiveSearcher<'p, u8>>

The consumer associated with this needle.
Source§

fn into_searcher(self) -> Self::Searcher

Produces a searcher for this needle.
Source§

fn into_consumer(self) -> Self::Consumer

Produces a consumer for this needle. Read more
Source§

impl Ord for Wtf8

Source§

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

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

impl PartialEq for Wtf8

Source§

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

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

fn ne(&self, other: &Self) -> 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: &Self) -> Option<Ordering>

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

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

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

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

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

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

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

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

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

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