Skip to main content

Serialize

Trait Serialize 

Source
pub trait Serialize {
    type Error;

    // Required methods
    fn serialized_len(&self) -> usize;
    fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Self::Error>;

    // Provided method
    fn to_bytes(&self) -> Vec<u8> 
       where Self::Error: Debug { ... }
}
Expand description

Serialize a DVB structure back to bytes. Split from Parse so owned and borrowed variants of the same type can implement Serialize without carrying a lifetime.

Required Associated Types§

Source

type Error

The error type this implementer returns (usually the same as the corresponding Parse impl, but need not be).

Required Methods§

Source

fn serialized_len(&self) -> usize

Number of bytes serialize_into will write.

Source

fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Self::Error>

Write the serialised form into buf. Returns the number of bytes written (always equal to serialized_len()).

Provided Methods§

Source

fn to_bytes(&self) -> Vec<u8>
where Self::Error: Debug,

Convenience: allocate a Vec and serialise into it. Panics only if serialize_into misreports serialized_len() — a contract every implementer is responsible for upholding.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§