Trait EncodeAsFields

Source
pub trait EncodeAsFields {
    // Required method
    fn encode_as_fields_to<R: TypeResolver>(
        &self,
        fields: &mut dyn FieldIter<'_, R::TypeId>,
        types: &R,
        out: &mut Vec<u8>,
    ) -> Result<(), Error>;

    // Provided method
    fn encode_as_fields<R: TypeResolver>(
        &self,
        fields: &mut dyn FieldIter<'_, R::TypeId>,
        types: &R,
    ) -> Result<Vec<u8>, Error> { ... }
}
Expand description

This is similar to EncodeAsType, except that it can be implemented on types that can be encoded to bytes given a list of fields instead of a single type ID. This is generally implemented just for tuple and struct types, and is automatically implemented via the EncodeAsType macro.

Required Methods§

Source

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Given some fields describing the shape of a type, attempt to encode to that shape.

Provided Methods§

Source

fn encode_as_fields<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, ) -> Result<Vec<u8>, Error>

This is a helper function which internally calls EncodeAsFields::encode_as_fields_to. Prefer to implement that instead.

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<K: AsRef<str>, V: EncodeAsType> EncodeAsFields for BTreeMap<K, V>

Source§

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Source§

impl<T: EncodeAsFields> EncodeAsFields for Box<T>

Source§

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Source§

impl<T: EncodeAsFields> EncodeAsFields for Rc<T>

Source§

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Source§

impl<T: EncodeAsFields> EncodeAsFields for Arc<T>

Source§

fn encode_as_fields_to<R: TypeResolver>( &self, fields: &mut dyn FieldIter<'_, R::TypeId>, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>

Implementors§