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
use crate::Context;

use super::{Decode, Decoder};

/// A pack that can construct decoders.
pub trait PackDecoder<'de> {
    /// Context associated with the decoder.
    type Cx: ?Sized + Context;
    /// The encoder to use for the pack.
    type DecodeNext<'this>: Decoder<
        'de,
        Cx = Self::Cx,
        Error = <Self::Cx as Context>::Error,
        Mode = <Self::Cx as Context>::Mode,
    >
    where
        Self: 'this;

    /// Return decoder to unpack the next element.
    #[must_use = "Decoders must be consumed"]
    fn decode_next(&mut self) -> Result<Self::DecodeNext<'_>, <Self::Cx as Context>::Error>;

    /// Unpack a value of the given type.
    #[inline]
    fn next<T>(&mut self) -> Result<T, <Self::Cx as Context>::Error>
    where
        Self: Sized,
        T: Decode<'de, <Self::Cx as Context>::Mode>,
    {
        self.decode_next()?.decode()
    }
}