musli_core/en/
variant_encoder.rsuse crate::Context;
use super::{Encode, Encoder};
#[must_use = "Must call end_variant to finish encoding"]
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;
#[must_use = "Encoders must be consumed"]
fn encode_tag(&mut self) -> Result<Self::EncodeTag<'_>, <Self::Cx as Context>::Error>;
#[must_use = "Encoders must be consumed"]
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>;
#[inline]
fn insert_variant<T, V>(
mut 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>,
{
self.encode_tag()?.encode(tag)?;
self.encode_data()?.encode(value)?;
self.finish_variant()
}
}