EncodableElement

Trait EncodableElement 

Source
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§

Source

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§

Source

fn to_vec(&self, ctx: &mut EncoderContext) -> Vec<u8>

Serialize the object into a bytes array.

Source

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

Source

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.

Implementations on Foreign Types§

Source§

impl EncodableElement for bool

Source§

fn to_buffer(&self, _ctx: &mut EncoderContext, buf: &mut [u8])

Source§

impl EncodableElement for u64

Source§

fn to_buffer(&self, _ctx: &mut EncoderContext, buf: &mut [u8])

Source§

impl EncodableElement for ()

Source§

fn to_buffer(&self, _ctx: &mut EncoderContext, _buf: &mut [u8])

Source§

impl EncodableElement for usize

Source§

fn to_buffer(&self, ctx: &mut EncoderContext, buf: &mut [u8])

Source§

impl<T> EncodableElement for Option<T>

Source§

fn to_buffer(&self, ctx: &mut EncoderContext, buf: &mut [u8])

Source§

impl<T> EncodableElement for PhantomData<T>

Source§

fn to_buffer(&self, _ctx: &mut EncoderContext, _buf: &mut [u8])

Implementors§