Trait ToBytes

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

Convert a field to binary representation

Required Methods§

Source

fn binary_size(&self) -> usize

Return the number of bytes needed to store the field

Source

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

Write the binary representation to writer

Source

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§

Source§

impl ToBytes for &CStr

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for &UnixPath

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for &[u8]

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for IpAddr

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for bool

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for i8

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for i16

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for i32

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for i64

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for u8

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for u16

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for u32

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for u64

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for Ipv4Addr

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for Ipv6Addr

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for SocketAddrV4

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for SocketAddrV6

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

impl ToBytes for Duration

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Source§

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

Source§

fn binary_size(&self) -> usize

Source§

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

Source§

fn default_repr() -> impl ToBytes

Implementors§