use 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 EncodeValue<'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_value(&mut self) -> Result<Self::EncodeValue<'_>, <Self::Cx as Context>::Error>;
fn end_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_value()?.encode(value)?;
self.end_variant()
}
}