musli_core/de/
variant_decoder.rs

1use crate::Context;
2
3use super::Decoder;
4
5/// Trait governing how to decode a variant.
6pub trait VariantDecoder<'de> {
7    /// Context associated with the decoder.
8    type Cx: ?Sized + Context;
9    /// The decoder to use for the variant tag.
10    type DecodeTag<'this>: Decoder<
11        'de,
12        Cx = Self::Cx,
13        Error = <Self::Cx as Context>::Error,
14        Mode = <Self::Cx as Context>::Mode,
15    >
16    where
17        Self: 'this;
18    /// The decoder to use for the variant value.
19    type DecodeValue<'this>: Decoder<
20        'de,
21        Cx = Self::Cx,
22        Error = <Self::Cx as Context>::Error,
23        Mode = <Self::Cx as Context>::Mode,
24    >
25    where
26        Self: 'this;
27
28    /// Return the decoder for the first value in the pair.
29    ///
30    /// If this is a map the first value would be the key of the map, if this is
31    /// a struct the first value would be the field of the struct.
32    #[must_use = "Decoders must be consumed"]
33    fn decode_tag(&mut self) -> Result<Self::DecodeTag<'_>, <Self::Cx as Context>::Error>;
34
35    /// Decode the second value in the pair..
36    #[must_use = "Decoders must be consumed"]
37    fn decode_value(&mut self) -> Result<Self::DecodeValue<'_>, <Self::Cx as Context>::Error>;
38}