[][src]Trait frombytes::FromBytes

pub trait FromBytes: Sized {
    type Error;
    fn from_bytes(bytes: &mut Bytes<'_>) -> Result<Self, Self::Error>;
}

Fallible conversion of bytes to a new type.

Examples

use frombytes::{Bytes, Error, FromBytes};

struct MyStruct {
    a: u32,
    b: i16,
}

impl FromBytes for MyStruct {
    // we simply use the same error that primitives use
    // but any error could be used
    type Error = Error;

    fn from_bytes(bytes: &mut Bytes) -> Result<Self, Self::Error> {
        // uses type inference to know to read a `u32`
        let a = bytes.read()?;
        // uses type inference to know to read a `i16`
        let b = bytes.read()?;
        Ok(Self { a, b })
    }
}

Associated Types

type Error

The associated error which can be returned from parsing.

All primitive types as well as radiotap fields implementing this trait set this error to Error.

Loading content...

Required methods

fn from_bytes(bytes: &mut Bytes<'_>) -> Result<Self, Self::Error>

Construct a type from bytes.

This method is often used implicitly through Bytes's read method.

Loading content...

Implementations on Foreign Types

impl FromBytes for u8[src]

type Error = Error

impl FromBytes for u16[src]

type Error = Error

impl FromBytes for u32[src]

type Error = Error

impl FromBytes for u64[src]

type Error = Error

impl FromBytes for u128[src]

type Error = Error

impl FromBytes for i8[src]

type Error = Error

impl FromBytes for i16[src]

type Error = Error

impl FromBytes for i32[src]

type Error = Error

impl FromBytes for i64[src]

type Error = Error

impl FromBytes for i128[src]

type Error = Error

impl<T, E> FromBytes for [T; 1] where
    T: FromBytes<Error = E> + Default
[src]

type Error = E

impl<T, E> FromBytes for [T; 2] where
    T: FromBytes<Error = E> + Default
[src]

type Error = E

impl<T, E> FromBytes for [T; 3] where
    T: FromBytes<Error = E> + Default
[src]

type Error = E

impl<T, E> FromBytes for [T; 4] where
    T: FromBytes<Error = E> + Default
[src]

type Error = E

Loading content...

Implementors

Loading content...