multiversx_sc_codec/multi/
top_de_multi.rs

1use crate::{DecodeError, DecodeErrorHandler, DefaultErrorHandler, TopDecode, TopDecodeMultiInput};
2
3pub trait TopDecodeMulti: Sized {
4    /// Used to optimize single value loading of endpoint arguments.
5    const IS_SINGLE_VALUE: bool = false;
6
7    fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>
8    where
9        I: TopDecodeMultiInput,
10    {
11        Self::multi_decode_or_handle_err(input, DefaultErrorHandler)
12    }
13
14    fn multi_decode_or_handle_err<I, H>(input: &mut I, h: H) -> Result<Self, H::HandledErr>
15    where
16        I: TopDecodeMultiInput,
17        H: DecodeErrorHandler,
18    {
19        match Self::multi_decode(input) {
20            Ok(v) => Ok(v),
21            Err(e) => Err(h.handle_error(e)),
22        }
23    }
24}
25
26/// All single top decode types also work as multi-value decode types.
27impl<T> TopDecodeMulti for T
28where
29    T: TopDecode,
30{
31    const IS_SINGLE_VALUE: bool = true;
32
33    fn multi_decode_or_handle_err<I, H>(input: &mut I, h: H) -> Result<Self, H::HandledErr>
34    where
35        I: TopDecodeMultiInput,
36        H: DecodeErrorHandler,
37    {
38        input.next_value(h)
39    }
40}