Skip to main content

FromBytes

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".

Implementations on Foreign Types§

Source§

impl FromBytes<'_> for Duration

Source§

impl FromBytes<'_> for IpAddr

Source§

impl FromBytes<'_> for Ipv4Addr

Source§

impl FromBytes<'_> for Ipv6Addr

Source§

impl FromBytes<'_> for SocketAddrV4

Source§

impl FromBytes<'_> for SocketAddrV6

Source§

impl FromBytes<'_> for bool

Source§

impl FromBytes<'_> for i8

Source§

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

Source§

impl FromBytes<'_> for i16

Source§

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

Source§

impl FromBytes<'_> for i32

Source§

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

Source§

impl FromBytes<'_> for i64

Source§

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

Source§

impl FromBytes<'_> for u8

Source§

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

Source§

impl FromBytes<'_> for u16

Source§

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

Source§

impl FromBytes<'_> for u32

Source§

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

Source§

impl FromBytes<'_> for u64

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<'a> FromBytes<'a> for &'a Path<UnixEncoding>

Source§

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

Source§

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

Source§

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

Implementors§