Skip to main content

Utf8

Enum Utf8 

Source
pub enum Utf8 {}
Expand description

Namespace for UTF-8 constants and byte classification helpers.

Implementations§

Source§

impl Utf8

Source

pub const MAX_UNITS_PER_CHAR: usize = 4

Maximum number of UTF-8 bytes needed for one Unicode scalar value.

Source

pub const MAX_BYTES_PER_CHAR: usize = Self::MAX_UNITS_PER_CHAR

Maximum number of UTF-8 bytes needed for one Unicode scalar value.

Source

pub const fn is_single_byte(byte: u8) -> bool

Tests whether a byte encodes an ASCII scalar value by itself.

§Parameters
  • byte: The byte to test.
§Returns

Returns true if byte is in 0x00..=0x7F.

Source

pub const fn is_leading_byte(byte: u8) -> bool

Tests whether a byte can lead a multi-byte UTF-8 sequence.

§Parameters
  • byte: The byte to test.
§Returns

Returns true if byte is in 0xC2..=0xF4.

Source

pub const fn is_continuation_byte(byte: u8) -> bool

Tests whether a byte is a UTF-8 continuation byte.

§Parameters
  • byte: The byte to test.
§Returns

Returns true if byte matches the 10xxxxxx continuation pattern.

Source

pub const fn byte_len_from_leading_byte(byte: u8) -> Option<usize>

Returns the complete UTF-8 sequence length implied by a leading byte.

§Parameters
  • byte: The first byte of the UTF-8 sequence.
§Returns

Returns Some(1..=4) for valid ASCII or leading bytes, and None for continuation bytes or invalid leading bytes.

Source

pub const fn byte_len(ch: char) -> usize

Returns the number of UTF-8 bytes needed for ch.

§Parameters
  • ch: The character to size.
§Returns

Returns 1, 2, 3, or 4.

Auto Trait Implementations§

§

impl Freeze for Utf8

§

impl RefUnwindSafe for Utf8

§

impl Send for Utf8

§

impl Sync for Utf8

§

impl Unpin for Utf8

§

impl UnsafeUnpin for Utf8

§

impl UnwindSafe for Utf8

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

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.