musli_core::en

Trait VariantEncoder

Source
pub trait VariantEncoder {
    type Cx: ?Sized + Context;
    type Ok;
    type EncodeTag<'this>: Encoder<Cx = Self::Cx, Ok = Self::Ok, Error = <Self::Cx as Context>::Error, Mode = <Self::Cx as Context>::Mode>
       where Self: 'this;
    type EncodeData<'this>: Encoder<Cx = Self::Cx, Ok = Self::Ok, Error = <Self::Cx as Context>::Error, Mode = <Self::Cx as Context>::Mode>
       where Self: 'this;

    // Required methods
    fn encode_tag(
        &mut self,
    ) -> Result<Self::EncodeTag<'_>, <Self::Cx as Context>::Error>;
    fn encode_data(
        &mut self,
    ) -> Result<Self::EncodeData<'_>, <Self::Cx as Context>::Error>;
    fn finish_variant(self) -> Result<Self::Ok, <Self::Cx as Context>::Error>;

    // Provided method
    fn insert_variant<T, V>(
        self,
        tag: T,
        value: V,
    ) -> Result<Self::Ok, <Self::Cx as Context>::Error>
       where Self: Sized,
             T: Encode<<Self::Cx as Context>::Mode>,
             V: Encode<<Self::Cx as Context>::Mode> { ... }
}
Expand description

Trait governing how to encode a variant.

Required Associated Types§

Source

type Cx: ?Sized + Context

Context associated with the encoder.

Source

type Ok

Result type of the encoder.

Source

type EncodeTag<'this>: Encoder<Cx = Self::Cx, Ok = Self::Ok, Error = <Self::Cx as Context>::Error, Mode = <Self::Cx as Context>::Mode> where Self: 'this

The encoder returned when advancing the map encoder to encode the key.

Source

type EncodeData<'this>: Encoder<Cx = Self::Cx, Ok = Self::Ok, Error = <Self::Cx as Context>::Error, Mode = <Self::Cx as Context>::Mode> where Self: 'this

The encoder returned when advancing the map encoder to encode the value.

Required Methods§

Source

fn encode_tag( &mut self, ) -> Result<Self::EncodeTag<'_>, <Self::Cx as Context>::Error>

Return the encoder for the first element in the variant.

Source

fn encode_data( &mut self, ) -> Result<Self::EncodeData<'_>, <Self::Cx as Context>::Error>

Return encoder for the second element in the variant.

Source

fn finish_variant(self) -> Result<Self::Ok, <Self::Cx as Context>::Error>

End the variant encoder.

Provided Methods§

Source

fn insert_variant<T, V>( self, tag: T, value: V, ) -> Result<Self::Ok, <Self::Cx as Context>::Error>
where Self: Sized, T: Encode<<Self::Cx as Context>::Mode>, V: Encode<<Self::Cx as Context>::Mode>,

Insert the variant immediately.

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§