use crate::{Allocator, Context};
use super::{Decode, Decoder, EntriesDecoder, EntryDecoder, SizeHint};
pub trait MapDecoder<'de> {
type Cx: Context<Error = Self::Error, Allocator = Self::Allocator>;
type Error;
type Allocator: Allocator;
type Mode: 'static;
type DecodeEntry<'this>: EntryDecoder<
'de,
Cx = Self::Cx,
Error = Self::Error,
Allocator = Self::Allocator,
Mode = Self::Mode,
>
where
Self: 'this;
type DecodeRemainingEntries<'this>: EntriesDecoder<
'de,
Cx = Self::Cx,
Error = Self::Error,
Allocator = Self::Allocator,
Mode = Self::Mode,
>
where
Self: 'this;
fn cx(&self) -> Self::Cx;
#[inline]
fn size_hint(&self) -> SizeHint {
SizeHint::any()
}
#[must_use = "Decoders must be consumed"]
fn decode_entry(&mut self) -> Result<Option<Self::DecodeEntry<'_>>, Self::Error>;
fn decode_remaining_entries(&mut self)
-> Result<Self::DecodeRemainingEntries<'_>, Self::Error>;
fn entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
where
K: Decode<'de, Self::Mode, Self::Allocator>,
V: Decode<'de, Self::Mode, Self::Allocator>,
{
let Some(mut entry) = self.decode_entry()? else {
return Ok(None);
};
let key = entry.decode_key()?.decode()?;
let value = entry.decode_value()?.decode()?;
Ok(Some((key, value)))
}
}