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