multiversx_sc/io/
arg_loader_single.rs

1use core::marker::PhantomData;
2
3use crate::codec::{DecodeErrorHandler, TopDecodeMultiInput};
4
5use crate::{
6    api::{EndpointArgumentApi, ErrorApi, ManagedTypeApi},
7    io::ArgDecodeInput,
8};
9
10/// Loads a single-value argument. Behaves as if only the argument at `current_index` exists, nothing after.
11///
12/// Only used in `ArgNestedTuple`, do not use directly.
13#[derive(Default)]
14pub(super) struct EndpointSingleArgLoader<AA>
15where
16    AA: ManagedTypeApi + ErrorApi + EndpointArgumentApi,
17{
18    _phantom: PhantomData<AA>,
19    current_index: i32,
20}
21
22impl<AA> EndpointSingleArgLoader<AA>
23where
24    AA: ManagedTypeApi + ErrorApi + EndpointArgumentApi,
25{
26    pub fn new(index: i32) -> Self {
27        EndpointSingleArgLoader {
28            _phantom: PhantomData,
29            current_index: index,
30        }
31    }
32}
33
34impl<AA> TopDecodeMultiInput for EndpointSingleArgLoader<AA>
35where
36    AA: ManagedTypeApi + ErrorApi + EndpointArgumentApi,
37{
38    type ValueInput = ArgDecodeInput<AA>;
39
40    fn has_next(&self) -> bool {
41        false
42    }
43
44    fn next_value_input<H>(&mut self, _h: H) -> Result<Self::ValueInput, H::HandledErr>
45    where
46        H: DecodeErrorHandler,
47    {
48        let arg_input = ArgDecodeInput::new(self.current_index);
49        Ok(arg_input)
50    }
51
52    fn flush_ignore<H>(&mut self, _h: H) -> Result<(), H::HandledErr>
53    where
54        H: DecodeErrorHandler,
55    {
56        Ok(())
57    }
58}