ByteType

Enum ByteType 

Source
pub enum ByteType {
    None,
    Ascii(u8),
    One(u8),
    Two(u8),
    Three(u8),
    FourOrMore(u8),
    Continuation(u8),
}
Expand description

Represents UTF-8 byte type based on the most significant bits the given byte

Examples

use utf8_rune::ByteType;
let f0 = ByteType::from(0xf0u8);
assert_eq!(f0, ByteType::FourOrMore(0xF0));
assert_eq!(f0.len(), 4);
assert_eq!(f0.is_ascii(), false);
assert_eq!(f0.is_continuation(), false);
use utf8_rune::ByteType;
let e4 = ByteType::from(0xE4u8);
assert_eq!(e4, ByteType::Three(0xE4));
assert_eq!(e4.len(), 3);
assert_eq!(e4.is_ascii(), false);
assert_eq!(e4.is_continuation(), false);
use utf8_rune::ByteType;
let c3 = ByteType::from(0xC3u8);
assert_eq!(c3, ByteType::Two(0xC3));
assert_eq!(c3.len(), 2);
assert_eq!(c3.is_ascii(), false);
assert_eq!(c3.is_continuation(), false);
use utf8_rune::ByteType;
let g = ByteType::from(b'g');
assert_eq!(g, ByteType::Ascii(0x67));
assert_eq!(g.len(), 1);
assert_eq!(g.is_ascii(), true);
assert_eq!(g.is_continuation(), false);
use utf8_rune::ByteType;
let g = ByteType::from(0x80u8);
assert_eq!(g, ByteType::Continuation(0x80));
assert_eq!(g.len(), 1);
assert_eq!(g.is_ascii(), false);
assert_eq!(g.is_continuation(), true);

Variants§

§

None

§

Ascii(u8)

§

One(u8)

§

Two(u8)

§

Three(u8)

§

FourOrMore(u8)

§

Continuation(u8)

Implementations§

Source§

impl ByteType

Source

pub fn new(byte: u8) -> ByteType

Source

pub fn name(&self) -> &'static str

Source

pub fn byte(&self) -> u8

Source

pub fn len(&self) -> usize

Source

pub fn is_ascii(&self) -> bool

Source

pub fn is_continuation(&self) -> bool

Source

pub fn has_rune_delta(&self) -> bool

Trait Implementations§

Source§

impl Clone for ByteType

Source§

fn clone(&self) -> ByteType

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 ByteType

Source§

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

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

impl From<&u8> for ByteType

Source§

fn from(byte: &u8) -> ByteType

Converts to this type from the input type.
Source§

impl From<u16> for ByteType

Source§

fn from(bytes: u16) -> ByteType

Converts to this type from the input type.
Source§

impl From<u32> for ByteType

Source§

fn from(bytes: u32) -> ByteType

Converts to this type from the input type.
Source§

impl From<u64> for ByteType

Source§

fn from(bytes: u64) -> ByteType

Converts to this type from the input type.
Source§

impl From<u8> for ByteType

Source§

fn from(byte: u8) -> ByteType

Converts to this type from the input type.
Source§

impl From<usize> for ByteType

Source§

fn from(bytes: usize) -> ByteType

Converts to this type from the input type.
Source§

impl PartialEq for ByteType

Source§

fn eq(&self, other: &ByteType) -> 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 Copy for ByteType

Source§

impl Eq for ByteType

Source§

impl StructuralPartialEq for ByteType

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.