novax_data/types/
multi_value.rs

1use crate::types::native::NativeConvertible;
2use crate::types::managed::ManagedConvertible;
3use multiversx_sc_codec::TopEncodeMulti;
4
5macro_rules! multi_value_native_convertible_impl {
6        ($(($mv_struct:ident $len:tt $($n:tt $name:ident $native:ident)+) )+) => {
7        $(
8            use multiversx_sc_codec::multi_types::$mv_struct;
9            impl<$($name: NativeConvertible,)+> NativeConvertible for $mv_struct<$($name,)+> {
10                type Native = ($($name::Native,)+);
11
12                fn to_native(&self) -> Self::Native {
13                    ($((self.0).$n.to_native()),+)
14                }
15            }
16        
17            impl<$($name: TopEncodeMulti, $native: ManagedConvertible<$name>,)+> ManagedConvertible<$mv_struct<$($name,)+>> for ($($native,)+) {
18                fn to_managed(&self) -> $mv_struct<$($name,)+> {
19                    $mv_struct::from(
20                        (
21                           ($(self.$n.to_managed()),+)
22                        )
23                    )
24                }
25            }
26        )+
27    }
28}
29
30multi_value_native_convertible_impl! {
31    (MultiValue2   2 0 T0 C0 1 T1 C1)
32    (MultiValue3   3 0 T0 C0 1 T1 C1 2 T2 C2)
33    (MultiValue4   4 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3)
34    (MultiValue5   5 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4)
35    (MultiValue6   6 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5)
36    (MultiValue7   7 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5 6 T6 C6)
37    (MultiValue8   8 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5 6 T6 C6 7 T7 C7)
38    (MultiValue9   9 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5 6 T6 C6 7 T7 C7 8 T8 C8)
39    (MultiValue10 10 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5 6 T6 C6 7 T7 C7 8 T8 C8 9 T9 C9)
40    (MultiValue11 11 0 T0 C0 1 T1 C1 2 T2 C2 3 T3 C3 4 T4 C4 5 T5 C5 6 T6 C6 7 T7 C7 8 T8 C8 9 T9 C9 10 T10 C10)
41}