musli_core/de/
entry_decoder.rs

1use crate::Context;
2
3use super::{Decoder, SizeHint};
4
5/// Trait governing how to decode a map entry.
6pub trait EntryDecoder<'de> {
7    /// Context associated with the decoder.
8    type Cx: ?Sized + Context;
9    /// The decoder to use for a tuple field index.
10    type DecodeKey<'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 a tuple field value.
19    type DecodeValue: Decoder<
20        'de,
21        Cx = Self::Cx,
22        Error = <Self::Cx as Context>::Error,
23        Mode = <Self::Cx as Context>::Mode,
24    >;
25
26    /// Get a size hint for the size of the map being decoded.
27    #[inline]
28    fn size_hint(&self) -> SizeHint {
29        SizeHint::any()
30    }
31
32    /// Return the decoder for the first value in the pair.
33    ///
34    /// If this is a map the first value would be the key of the map, if this is
35    /// a struct the first value would be the field of the struct.
36    #[must_use = "Decoders must be consumed"]
37    fn decode_key(&mut self) -> Result<Self::DecodeKey<'_>, <Self::Cx as Context>::Error>;
38
39    /// Decode the second value in the pair..
40    #[must_use = "Decoders must be consumed"]
41    fn decode_value(self) -> Result<Self::DecodeValue, <Self::Cx as Context>::Error>;
42}