Trait ToBytes

pub trait ToBytes {
    // Required methods
    fn binary_size(&self) -> usize;
    fn write<W>(&self, writer: W) -> Result<(), Error>
       where W: Write;
    fn default_repr() -> impl ToBytes;
}
Expand description

Convert a field to binary representation

Required Methods§

fn binary_size(&self) -> usize

Return the number of bytes needed to store the field

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

Write the binary representation to writer

fn default_repr() -> impl ToBytes

Return the default representation for the field type

Note: this does not need to be the same type as the implementing type. For example, an empty C-style string can be represented e.g. by returning 0u8.

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 ToBytes for &CStr

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for &Path<UnixEncoding>

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for &[u8]

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for IpAddr

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for bool

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for i8

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for i16

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for i32

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for i64

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for u8

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for u16

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for u32

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for u64

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for Ipv4Addr

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for Ipv6Addr

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for SocketAddrV4

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for SocketAddrV6

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl ToBytes for Duration

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

§

impl<T> ToBytes for Option<T>
where T: ToBytes,

§

fn binary_size(&self) -> usize

§

fn write<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

§

fn default_repr() -> impl ToBytes

Implementors§

§

impl ToBytes for NoDefault

§

impl ToBytes for Bool

§

impl ToBytes for CStrArray<'_>

§

impl ToBytes for Fd

§

impl ToBytes for Gid

§

impl ToBytes for IpNet

§

impl ToBytes for Ipv4Net

§

impl ToBytes for Ipv6Net

§

impl ToBytes for L4Proto

§

impl ToBytes for Pid

§

impl ToBytes for Port

§

impl ToBytes for SigSet

§

impl ToBytes for SigType

§

impl ToBytes for SockFamily

§

impl ToBytes for SyscallId

§

impl ToBytes for SyscallResult

§

impl ToBytes for SystemTime

§

impl ToBytes for Uid

§

impl<'a> ToBytes for CStrPairArray<'a>

§

impl<'a> ToBytes for RelativePath<'a>

Source§

impl<T> ToBytes for JsonPayload<T>
where T: Serialize,