Trait ToBinary

Source
pub unsafe trait ToBinary {
    const POD: bool = false;

    // Required method
    fn encode_binary(&self, encoder: &mut BytesWriter<'_>);
}
Expand description

A trait for converting a value to a compact binary representation.

This trait is used to append the binary encoding of a type to the end of a provided encoder. For more details on the specific binary implementation, see the binary module.

§Safety

If you use the default implementation (i.e., POD = false), this trait is always safe to implement. When POD is set to true, it indicates that this type can be directly memory-copied to the output, maintaining the same representation as if it were encoded field-by-field.

§Constraints for POD = true:

  1. Every bit pattern must be valid for the type and layout.
  2. There must be no padding between fields.
  3. Fields must be laid out in the same order as they would be encoded and decoded via the encode_binary function.

§Notes

  • The encode_binary function should always write a value, even in error cases. There is no error return;

Provided Associated Constants§

Source

const POD: bool = false

Indicates whether the type is Plain Old Data (POD).

When true, the type can be safely memory-copied. Default is false.

Required Methods§

Source

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Encodes the type into its binary representation.

This function should append the binary encoding of self to the provided encoder.

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 ToBinary for bool

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for char

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for f32

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for f64

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for i8

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for i16

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for i32

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for i64

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for i128

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for str

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for u8

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for u16

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for u32

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for u64

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for u128

Source§

const POD: bool = true

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for String

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl ToBinary for Duration

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<'a, T: ToBinary + ToOwned + ?Sized> ToBinary for Cow<'a, T>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<K: ToBinary, S> ToBinary for HashSet<K, S>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<K: ToBinary, V: ToBinary, S> ToBinary for HashMap<K, V, S>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T0: ToBinary> ToBinary for (T0,)

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T0: ToBinary, T1: ToBinary> ToBinary for (T0, T1)

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T0: ToBinary, T1: ToBinary, T2: ToBinary> ToBinary for (T0, T1, T2)

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary + ?Sized> ToBinary for &T

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary + ?Sized> ToBinary for &mut T

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary> ToBinary for Option<T>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary> ToBinary for [T]

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary> ToBinary for Box<T>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary> ToBinary for Vec<T>

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Source§

impl<T: ToBinary, const N: usize> ToBinary for [T; N]

Source§

const POD: bool = T::POD

Source§

fn encode_binary(&self, encoder: &mut BytesWriter<'_>)

Implementors§