Trait FromBytes

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§

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§

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§

§

impl FromBytes<'_> for IpAddr

§

impl FromBytes<'_> for bool

§

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

§

impl FromBytes<'_> for i8

§

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

§

impl FromBytes<'_> for i16

§

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

§

impl FromBytes<'_> for i32

§

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

§

impl FromBytes<'_> for i64

§

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

§

impl FromBytes<'_> for u8

§

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

§

impl FromBytes<'_> for u16

§

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

§

impl FromBytes<'_> for u32

§

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

§

impl FromBytes<'_> for u64

§

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

§

impl FromBytes<'_> for Ipv4Addr

§

impl FromBytes<'_> for Ipv6Addr

§

impl FromBytes<'_> for SocketAddrV4

§

impl FromBytes<'_> for SocketAddrV6

§

impl FromBytes<'_> for Duration

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

Implementors§

§

impl FromBytes<'_> for Bool

§

impl FromBytes<'_> for Fd

§

impl FromBytes<'_> for Gid

§

impl FromBytes<'_> for IpNet

§

impl FromBytes<'_> for Ipv4Net

§

impl FromBytes<'_> for Ipv6Net

§

impl FromBytes<'_> for L4Proto

§

impl FromBytes<'_> for Pid

§

impl FromBytes<'_> for Port

§

impl FromBytes<'_> for SigSet

§

impl FromBytes<'_> for SigType

§

impl FromBytes<'_> for SockFamily

§

impl FromBytes<'_> for SyscallId

§

impl FromBytes<'_> for SyscallResult

§

impl FromBytes<'_> for SystemTime

§

impl FromBytes<'_> for Uid

§

impl<'a> FromBytes<'a> for CStrArray<'a>

§

impl<'a> FromBytes<'a> for CStrPairArray<'a>

§

impl<'a> FromBytes<'a> for RelativePath<'a>

Source§

impl<'a, T> FromBytes<'a> for JsonPayload<T>