musli_core/de/
map_decoder.rs1use crate::{Allocator, Context};
2
3use super::{Decode, Decoder, EntriesDecoder, EntryDecoder, SizeHint};
4
5pub trait MapDecoder<'de> {
7 type Cx: Context<Error = Self::Error, Allocator = Self::Allocator>;
9 type Error;
11 type Allocator: Allocator;
13 type Mode: 'static;
15 type DecodeEntry<'this>: EntryDecoder<
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 type DecodeRemainingEntries<'this>: EntriesDecoder<
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 fn cx(&self) -> Self::Cx;
38
39 #[inline]
41 fn size_hint(&self) -> SizeHint {
42 SizeHint::any()
43 }
44
45 #[must_use = "Decoders must be consumed"]
48 fn decode_entry(&mut self) -> Result<Option<Self::DecodeEntry<'_>>, Self::Error>;
49
50 fn decode_remaining_entries(&mut self)
52 -> Result<Self::DecodeRemainingEntries<'_>, Self::Error>;
53
54 fn entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
56 where
57 K: Decode<'de, Self::Mode, Self::Allocator>,
58 V: Decode<'de, Self::Mode, Self::Allocator>,
59 {
60 let Some(mut entry) = self.decode_entry()? else {
61 return Ok(None);
62 };
63
64 let key = entry.decode_key()?.decode()?;
65 let value = entry.decode_value()?.decode()?;
66 Ok(Some((key, value)))
67 }
68}