multiversx_sc/io/
arg_error_handler.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 core::{convert::Infallible, marker::PhantomData};

use crate::{
    api::{ErrorApi, ManagedTypeApi},
    codec::*,
    io::{signal_arg_de_error, ArgId},
};

#[derive(Clone)]
pub struct ArgErrorHandler<M>
where
    M: ManagedTypeApi + ErrorApi,
{
    _phantom: PhantomData<M>,
    pub arg_id: ArgId,
}

impl<M> Copy for ArgErrorHandler<M> where M: ManagedTypeApi + ErrorApi {}

impl<M> From<ArgId> for ArgErrorHandler<M>
where
    M: ManagedTypeApi + ErrorApi,
{
    fn from(arg_id: ArgId) -> Self {
        ArgErrorHandler {
            _phantom: PhantomData,
            arg_id,
        }
    }
}

impl<M> DecodeErrorHandler for ArgErrorHandler<M>
where
    M: ManagedTypeApi + ErrorApi,
{
    type HandledErr = Infallible;

    #[inline(always)]
    fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
        signal_arg_de_error::<M>(self.arg_id, err)
    }
}