stylus_sdk/abi/export/
internal.rs1use core::any::TypeId;
8
9use alloy_primitives::{Address, FixedBytes, Signed, Uint};
10
11use crate::abi::Bytes;
12
13pub struct InnerType {
15 pub name: String,
17 pub id: TypeId,
19}
20
21pub trait InnerTypes {
23 fn inner_types() -> Vec<InnerType> {
26 vec![]
27 }
28}
29
30impl<O, E> InnerTypes for Result<O, E>
31where
32 O: InnerTypes,
33 E: InnerTypes,
34{
35 fn inner_types() -> Vec<InnerType> {
36 let mut out = O::inner_types();
37 out.extend(E::inner_types());
38 out
39 }
40}
41
42impl<T: InnerTypes> InnerTypes for Vec<T> {
43 fn inner_types() -> Vec<InnerType> {
44 T::inner_types()
45 }
46}
47
48impl<const N: usize, T: InnerTypes> InnerTypes for [T; N] {
49 fn inner_types() -> Vec<InnerType> {
50 T::inner_types()
51 }
52}
53
54macro_rules! impl_inner {
55 ($ty:ident $($rest:ident)+) => {
56 impl_inner!($ty);
57 impl_inner!($($rest)+);
58 };
59 ($ty:ident) => {
60 impl InnerTypes for $ty {}
61 };
62}
63
64impl_inner!(bool u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 String Address Bytes);
65
66impl<const B: usize, const L: usize> InnerTypes for Uint<B, L> {}
67impl<const B: usize, const L: usize> InnerTypes for Signed<B, L> {}
68impl<const N: usize> InnerTypes for FixedBytes<N> {}
69
70macro_rules! impl_tuple {
71 () => {
72 impl InnerTypes for () {}
73 };
74 ($first:ident $(, $rest:ident)*) => {
75 impl<$first: InnerTypes $(, $rest: InnerTypes)*> InnerTypes for ( $first $(, $rest)* , ) {
76 fn inner_types() -> Vec<InnerType> {
77 vec![]
78 }
79 }
80
81 impl_tuple! { $($rest),* }
82 };
83}
84
85impl_tuple!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X);