Trait FromBytes

Source
pub trait FromBytes<'a>: Sized {
    // Required method
    fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>;

    // Provided method
    fn from_maybe_bytes(
        buf: Option<&mut &'a [u8]>,
    ) -> Result<Self, FromBytesError> { ... }
}
Expand description

Deserialize a field from a byte buffer

Required Methods§

Source

fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>

Read the binary representation of a field and return the parsed representation

Note: the argument is a mutable reference to an immutable slice. While the contents of the slice cannot be modified, the slice itself can. Every call to from_bytes consumes a number of bytes from the beginning of the slice.

Provided Methods§

Source

fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> Result<Self, FromBytesError>

Read the binary representation of a field from a buffer that may or may not exist

The default implementation returns an error when the buffer does not exist, but the blanket impl for Option<T> effectively returns Ok(None)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromBytes<'_> for IpAddr

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for bool

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for i8

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for i16

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for i32

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for i64

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for u8

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for u16

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for u32

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for u64

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl FromBytes<'_> for Ipv4Addr

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for Ipv6Addr

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for SocketAddrV4

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for SocketAddrV6

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>

Source§

impl FromBytes<'_> for Duration

Source§

fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError>
where Self: Sized,

Source§

impl<'a> FromBytes<'a> for &'a CStr

Source§

fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>

Source§

impl<'a> FromBytes<'a> for &'a UnixPath

Source§

fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>

Source§

impl<'a> FromBytes<'a> for &'a [u8]

Source§

fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>

Source§

impl<'a, T> FromBytes<'a> for Option<T>
where T: Sized + FromBytes<'a> + 'a,

Source§

fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>

Source§

fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> Result<Self, FromBytesError>

Implementors§