musli_core/de/
variant_decoder.rs

1use crate::{Allocator, 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: Context<Error = Self::Error, Allocator = Self::Allocator>;
9    /// Error associated with decoding.
10    type Error;
11    /// The allocator associated with the decoder.
12    type Allocator: Allocator;
13    /// The mode of the decoder.
14    type Mode: 'static;
15    /// The decoder to use for the variant tag.
16    type DecodeTag<'this>: Decoder<
17            'de,
18            Cx = Self::Cx,
19            Error = Self::Error,
20            Allocator = Self::Allocator,
21            Mode = Self::Mode,
22        >
23    where
24        Self: 'this;
25    /// The decoder to use for the variant value.
26    type DecodeValue<'this>: Decoder<
27            'de,
28            Cx = Self::Cx,
29            Error = Self::Error,
30            Allocator = Self::Allocator,
31            Mode = Self::Mode,
32        >
33    where
34        Self: 'this;
35
36    /// Access the context associated with the decoder.
37    fn cx(&self) -> Self::Cx;
38
39    /// Return the decoder for the first value in the pair.
40    ///
41    /// If this is a map the first value would be the key of the map, if this is
42    /// a struct the first value would be the field of the struct.
43    #[must_use = "Decoders must be consumed"]
44    fn decode_tag(&mut self) -> Result<Self::DecodeTag<'_>, Self::Error>;
45
46    /// Decode the second value in the pair..
47    #[must_use = "Decoders must be consumed"]
48    fn decode_value(&mut self) -> Result<Self::DecodeValue<'_>, Self::Error>;
49}