pub trait EncodableElement: Element {
// Required method
fn to_buffer(&self, ctx: &mut EncoderContext, buf: &mut [u8]);
// Provided methods
fn to_vec(&self, ctx: &mut EncoderContext) -> Vec<u8> ⓘ { ... }
fn encode<'a>(
&self,
ctx: &mut EncoderContext,
buf: &'a mut [u8],
) -> &'a mut [u8] ⓘ { ... }
fn try_to_writer<W>(
&self,
writer: W,
ctx: &mut EncoderContext,
) -> Result<usize>
where W: Write { ... }
}Expand description
Element that can be encoded into a CDF file
Required Methods§
Sourcefn to_buffer(&self, ctx: &mut EncoderContext, buf: &mut [u8])
fn to_buffer(&self, ctx: &mut EncoderContext, buf: &mut [u8])
Write the type into the buffer.
§Panics
The buffer must, provided a correct definition of Element::len, contain enough bytes to
fully serialize the type. This can be checked via Element::validate_buffer.
Provided Methods§
Sourcefn to_vec(&self, ctx: &mut EncoderContext) -> Vec<u8> ⓘ
fn to_vec(&self, ctx: &mut EncoderContext) -> Vec<u8> ⓘ
Serialize the object into a bytes array.
Sourcefn encode<'a>(
&self,
ctx: &mut EncoderContext,
buf: &'a mut [u8],
) -> &'a mut [u8] ⓘ
fn encode<'a>( &self, ctx: &mut EncoderContext, buf: &'a mut [u8], ) -> &'a mut [u8] ⓘ
Read an element into the buffer, returning the remainder bytes
Assume its inside a validate buffer context
Sourcefn try_to_writer<W>(&self, writer: W, ctx: &mut EncoderContext) -> Result<usize>where
W: Write,
fn try_to_writer<W>(&self, writer: W, ctx: &mut EncoderContext) -> Result<usize>where
W: Write,
Send the bytes representation of an element to a writer
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.