1use crate::Context;
23use super::{Decoder, SizeHint};
45/// Trait governing how to decode a sequence of map pairs.
6///
7/// This trait exists so that decoders can implement a mode that is compatible
8/// with serde deserialization.
9///
10/// If you do not intend to implement this, then serde compatibility for your
11/// format might be degraded.
12#[must_use = "Must call end_entries to complete decoding"]
13pub trait EntriesDecoder<'de> {
14/// Context associated with the decoder.
15type Cx: ?Sized + Context;
16/// The decoder to use for a tuple field index.
17type DecodeEntryKey<'this>: Decoder<
18'de,
19 Cx = Self::Cx,
20 Error = <Self::Cx as Context>::Error,
21 Mode = <Self::Cx as Context>::Mode,
22 >
23where
24Self: 'this;
25/// The decoder to use for a tuple field value.
26type DecodeEntryValue<'this>: Decoder<
27'de,
28 Cx = Self::Cx,
29 Error = <Self::Cx as Context>::Error,
30 Mode = <Self::Cx as Context>::Mode,
31 >
32where
33Self: 'this;
3435/// Get a size hint for the size of the map being decoded.
36#[inline]
37fn size_hint(&self) -> SizeHint {
38 SizeHint::any()
39 }
4041/// Try to return the decoder for the first value in the pair.
42 ///
43 /// If this is a map the first value would be the key of the map, if this is
44 /// a struct the first value would be the field of the struct.
45#[must_use = "Decoders must be consumed"]
46fn decode_entry_key(
47&mut self,
48 ) -> Result<Option<Self::DecodeEntryKey<'_>>, <Self::Cx as Context>::Error>;
4950/// Decode the value in the map.
51#[must_use = "Decoders must be consumed"]
52fn decode_entry_value(
53&mut self,
54 ) -> Result<Self::DecodeEntryValue<'_>, <Self::Cx as Context>::Error>;
5556/// End entries decoding.
57fn end_entries(self) -> Result<(), <Self::Cx as Context>::Error>;
58}