Skip to main content

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 new<S: AsRef<Wtf8> + ?Sized>(value: &S) -> &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 const unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8

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

§Safety

value must contain valid WTF-8.

Source

pub fn from_bytes(b: &[u8]) -> Option<&Self>

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

Source

pub const fn len(&self) -> usize

Returns the length, in WTF-8 bytes.

Source

pub const fn is_empty(&self) -> bool

Source

pub const 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) -> Wtf8CodePoints<'_>

Returns an iterator for the string’s code points.

Source

pub fn code_point_indices(&self) -> Wtf8CodePointIndices<'_>

Returns an iterator for the string’s code points and their indices.

Source

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

Access raw bytes of WTF-8 data

Source

pub const fn as_str(&self) -> Result<&str, Utf8Error>

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 to_wtf8_buf(&self) -> Wtf8Buf

Creates an owned Wtf8Buf from a borrowed Wtf8.

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

pub const fn chunks(&self) -> Wtf8Chunks<'_>

Source

pub fn map_utf8<'a, I>( &'a self, f: impl Fn(&'a str) -> I, ) -> impl Iterator<Item = CodePoint>
where I: Iterator<Item = char>,

Source

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

Source

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

Boxes this Wtf8.

Source

pub fn empty_box() -> Box<Wtf8>

Creates a boxed, empty Wtf8.

Source

pub fn make_ascii_lowercase(&mut self)

Source

pub fn make_ascii_uppercase(&mut self)

Source

pub fn to_ascii_lowercase(&self) -> Wtf8Buf

Source

pub fn to_ascii_uppercase(&self) -> Wtf8Buf

Source

pub fn to_lowercase(&self) -> Wtf8Buf

Source

pub fn to_uppercase(&self) -> Wtf8Buf

Source

pub const fn is_ascii(&self) -> bool

Source

pub fn is_utf8(&self) -> bool

Source

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

Source

pub fn split(&self, pat: &Wtf8) -> impl Iterator<Item = &Self>

Source

pub fn splitn(&self, n: usize, pat: &Wtf8) -> impl Iterator<Item = &Self>

Source

pub fn rsplit(&self, pat: &Wtf8) -> impl Iterator<Item = &Self>

Source

pub fn rsplitn(&self, n: usize, pat: &Wtf8) -> impl Iterator<Item = &Self>

Source

pub fn trim(&self) -> &Self

Source

pub fn trim_start(&self) -> &Self

Source

pub fn trim_end(&self) -> &Self

Source

pub fn trim_start_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self

Source

pub fn trim_end_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self

Source

pub fn trim_matches(&self, f: impl Fn(CodePoint) -> bool) -> &Self

Source

pub fn find(&self, pat: &Wtf8) -> Option<usize>

Source

pub fn rfind(&self, pat: &Wtf8) -> Option<usize>

Source

pub fn find_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize>

Source

pub fn rfind_iter(&self, pat: &Wtf8) -> impl Iterator<Item = usize>

Source

pub fn contains(&self, pat: &Wtf8) -> bool

Source

pub fn contains_code_point(&self, pat: CodePoint) -> bool

Source

pub fn get(&self, range: impl RangeBounds<usize>) -> Option<&Self>

Source

pub fn ends_with(&self, w: impl AsRef<Wtf8>) -> bool

Source

pub fn starts_with(&self, w: impl AsRef<Wtf8>) -> bool

Source

pub fn strip_prefix(&self, w: impl AsRef<Wtf8>) -> Option<&Self>

Source

pub fn strip_suffix(&self, w: impl AsRef<Wtf8>) -> Option<&Self>

Source

pub fn replace(&self, from: &Wtf8, to: &Wtf8) -> Wtf8Buf

Source

pub fn replacen(&self, from: &Wtf8, to: &Wtf8, n: usize) -> Wtf8Buf

Trait Implementations§

Source§

impl AsRef<[u8]> for Wtf8

Source§

fn as_ref(&self) -> &[u8]

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

impl AsRef<Wtf8> for Wtf8

Source§

fn as_ref(&self) -> &Wtf8

Converts this type into a shared 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 AsRef<Wtf8> for str

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 Clone for Box<Wtf8>

Source§

fn clone(&self) -> Self

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 Wtf8

Formats the string in double quotes, with characters escaped according to char::escape_debug and unpaired surrogates represented as \u{xxxx}, where each x is a hexadecimal digit.

Source§

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

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

impl Default for &Wtf8

Source§

fn default() -> Self

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

impl Default for Box<Wtf8>

Source§

fn default() -> Self

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

impl Display for Wtf8

Formats the string with unpaired surrogates substituted with the replacement character, U+FFFD.

Source§

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

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

impl From<&Wtf8> for Box<Wtf8>

Source§

fn from(w: &Wtf8) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<&str> for Box<Wtf8>

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Box<AsciiStr>> for Box<Wtf8>

Source§

fn from(s: Box<AsciiStr>) -> Self

Converts to this type from the input type.
Source§

impl From<Box<str>> for Box<Wtf8>

Source§

fn from(s: Box<str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Box<Wtf8>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Wtf8Buf> for Box<Wtf8>

Source§

fn from(w: Wtf8Buf) -> Self

Converts to this type from the input type.
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 Index<Range<usize>> for Wtf8

Returns 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

Returns 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

Returns 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 Ord for Wtf8

Source§

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

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

impl PartialEq<str> for Wtf8

Source§

fn eq(&self, other: &str) -> 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 PartialEq for Wtf8

Source§

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

impl PartialOrd for Wtf8

Source§

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

Source§

type Owned = Wtf8Buf

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, buf: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Wtf8Concat for Wtf8

Source§

fn fmt_wtf8(&self, buf: &mut Wtf8Buf)

Source§

impl Eq for Wtf8

Source§

impl StructuralPartialEq 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 UnsafeUnpin 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