[−][src]Struct whasm::grammar::core::byte::Byte
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 Byte
s 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]
fn cmp(&self, other: &Byte) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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]
fn partial_cmp(&self, other: &Byte) -> Option<Ordering>
[src]
fn lt(&self, other: &Byte) -> bool
[src]
fn le(&self, other: &Byte) -> bool
[src]
fn gt(&self, other: &Byte) -> bool
[src]
fn ge(&self, other: &Byte) -> bool
[src]
impl Debug for Byte
[src]
impl Display for Byte
[src]
impl Hash for Byte
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,