[][src]Struct whasm::grammar::core::byte::Byte

pub struct Byte(pub u8);

Wrapper for a byte of information. It differs from an u8 on how it is deserialized. A Byte reads exactly one byte from the input iterator, while a u8 could potentially read several bytes (since unsigned integers are encoded using LEB-128).

A Byte takes exactly one byte of memory, and can be transmuted to u8. This is specially useful since it allows transmuting a vector of Bytes to a vector of u8.

Example

let mut iter = [0x8E].iter().copied();
let Byte(result) = deserialize(&mut iter).unwrap();
assert_eq!(result, 0x8E);

Deserialization will return an error if the iterator is exhausted while deserializing.

let mut iter = [0x00].iter().copied();
let Byte(_) = deserialize(&mut iter).unwrap();
let result: Result<Byte> = deserialize(&mut iter);
assert!(result.is_err());

Trait Implementations

impl Grammar for Byte[src]

fn deserialize<Iter: Iterator<Item = u8>>(iter: &mut Iter) -> Result<Self>[src]

Read a Byte from an Iterator<u8>. It returns Ok(Byte(_)) on success, and Error(Error::UnexpectedEndOfStream) if the iterator returns None.

Deserializing a Byte instead of using iter.next() is an easy way to convert the Option<u8> returned by the iterator into a Result<u8> with a meaningful error type.

impl Clone for Byte[src]

impl Copy for Byte[src]

impl Eq for Byte[src]

impl Ord for Byte[src]

impl PartialEq<Byte> for Byte[src]

impl PartialEq<u8> for Byte[src]

impl PartialEq<char> for Byte[src]

impl PartialOrd<Byte> for Byte[src]

impl Debug for Byte[src]

impl Display for Byte[src]

impl Hash for Byte[src]

impl StructuralPartialEq for Byte[src]

impl StructuralEq for Byte[src]

Auto Trait Implementations

impl Send for Byte

impl Sync for Byte

impl Unpin for Byte

impl UnwindSafe for Byte

impl RefUnwindSafe for Byte

Blanket Implementations

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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