[][src]Struct encode_unicode::Utf8Char

pub struct Utf8Char { /* fields omitted */ }

Store a char as UTF-8 so it can be borrowed as a str

Has the same size as char, and is a [u8;4] with the invariant that the first nth bytes are valid UTF-8, and the remaining are zero.

Methods

impl Utf8Char[src]

pub fn from_slice_start(src: &[u8]) -> Result<(Self, usize), InvalidUtf8Slice>[src]

Validate the start of a UTF-8 slice and store it. Also returns how many bytes were needed.

If it's a str and you know it contains only one codepoint, use .from_str() to skip the validation.

pub fn from_array(utf8: [u8; 4]) -> Result<Self, InvalidUtf8Array>[src]

Validate the array and store it.

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

Result is 1...4 and identical to .as_ref().len() or .as_char().len_utf8(). There is no .is_emty() because it would always return false.

pub fn to_char(self) -> char[src]

Convert from UTF-8 to UTF-32

pub fn to_slice(self, dst: &mut [u8]) -> Option<usize>[src]

Write the internal representation to a slice, and then returns the number of bytes written.

None is returned if the buffer is too small; then the buffer is left unmodified. A buffer of length four is always large enough.

pub fn to_array(self) -> ([u8; 4], usize)[src]

Expose the internal array and the number of used bytes.

Trait Implementations

impl PartialEq<Utf8Char> for Utf8Char[src]

impl AsRef<[u8]> for Utf8Char[src]

impl AsRef<str> for Utf8Char[src]

impl IntoIterator for Utf8Char[src]

type Item = u8

The type of the elements being iterated over.

type IntoIter = Utf8Iterator

Which kind of iterator are we turning this into?

Important traits for Utf8Iterator
fn into_iter(self) -> Utf8Iterator[src]

Iterate over the byte values.

impl Default for Utf8Char[src]

impl Ord for Utf8Char[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Clone for Utf8Char[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl From<char> for Utf8Char[src]

impl From<Utf8Char> for char[src]

impl From<Utf8Char> for Utf8Iterator[src]

impl Eq for Utf8Char[src]

impl Copy for Utf8Char[src]

impl PartialOrd<Utf8Char> for Utf8Char[src]

impl Debug for Utf8Char[src]

impl Hash for Utf8Char[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl Deref for Utf8Char[src]

type Target = str

The resulting type after dereferencing.

impl FromStr for Utf8Char[src]

type Err = FromStrError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, FromStrError>[src]

The string must contain exactly one codepoint

impl Borrow<[u8]> for Utf8Char[src]

impl Borrow<str> for Utf8Char[src]

Auto Trait Implementations

impl Send for Utf8Char

impl Sync for Utf8Char

Blanket Implementations

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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