musli_core/de/entry_decoder.rs
1use crate::{Allocator, 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: 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 a tuple field index.
16 type DecodeKey<'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 a tuple field value.
26 type DecodeValue: Decoder<
27 'de,
28 Cx = Self::Cx,
29 Error = Self::Error,
30 Allocator = Self::Allocator,
31 Mode = Self::Mode,
32 >;
33
34 /// Access the context associated with the decoder.
35 fn cx(&self) -> Self::Cx;
36
37 /// Get a size hint for the size of the map being decoded.
38 #[inline]
39 fn size_hint(&self) -> SizeHint {
40 SizeHint::any()
41 }
42
43 /// Return the decoder for the first value in the pair.
44 ///
45 /// If this is a map the first value would be the key of the map, if this is
46 /// a struct the first value would be the field of the struct.
47 #[must_use = "Decoders must be consumed"]
48 fn decode_key(&mut self) -> Result<Self::DecodeKey<'_>, Self::Error>;
49
50 /// Decode the second value in the pair..
51 #[must_use = "Decoders must be consumed"]
52 fn decode_value(self) -> Result<Self::DecodeValue, Self::Error>;
53}