firefly_types

Trait Encode

Source
pub trait Encode<'a>
where Self: Sized + Deserialize<'a> + Serialize,
{ // Provided methods fn decode(s: &'a [u8]) -> Result<Self, Error> { ... } fn encode_vec(&self) -> Result<Vec<u8>, Error> { ... } fn encode_buf<'b>(&self, buf: &'b mut [u8]) -> Result<&'b mut [u8], Error> { ... } fn size(&self) -> usize { ... } }

Provided Methods§

Source

fn decode(s: &'a [u8]) -> Result<Self, Error>

Load object from bytes generated by [Encode::encode].

§Errors

May return an error if the buffer does not contain a valid object.

Source

fn encode_vec(&self) -> Result<Vec<u8>, Error>

Encode the object as a Vec.

If you want to avoid dynamic allocations, use Encode::encode_buf instead.

§Errors

In theory, may return an error if any of the types cannot be serialized by postcard. However, all the types defined in this crate are very simple, so it shouldn’t happen.

Source

fn encode_buf<'b>(&self, buf: &'b mut [u8]) -> Result<&'b mut [u8], Error>

Encode the object using the buffer.

The buffer is required to avoid allocations on the crate side. Use Encode::size to calculate the required buffer size.

§Errors

May return an error if the buffer is not big enough.

Source

fn size(&self) -> usize

Calculate the buffer size required to encode the object.

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.

Implementors§

Source§

impl<'a> Encode<'a> for Request

Source§

impl<'a> Encode<'a> for Response

Source§

impl<'a> Encode<'a> for Badges<'a>

Source§

impl<'a> Encode<'a> for Boards<'a>

Source§

impl<'a> Encode<'a> for Meta<'a>

Source§

impl<'a> Encode<'a> for Settings

Source§

impl<'a> Encode<'a> for ShortMeta<'a>

Source§

impl<'a> Encode<'a> for Stats