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§
Required Methods§
Sourcefn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
Number of bytes serialize_into will write.
Provided Methods§
Sourcefn to_bytes(&self) -> Vec<u8> ⓘ
fn to_bytes(&self) -> Vec<u8> ⓘ
Convenience: allocate a Vec and serialise into it.
§Panics
Panics if serialize_into returns an error on a buffer of exactly
serialized_len() bytes. For values obtained by parsing real wire data
this never happens; it can only occur for a hand-constructed value
that violates a wire constraint (e.g. a section whose body exceeds the
12-bit section_length). When building values by hand and that’s a
possibility, call serialize_into and handle the
error instead.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".