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
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,
fn write<W>(&self, writer: W) -> Result<(), Error>where
W: Write,
Write the binary representation to writer
fn default_repr() -> impl ToBytes
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.