use core::any::TypeId;
use alloy_primitives::{Address, Bytes, FixedBytes, Signed, Uint};
pub struct InnerType {
pub name: String,
pub id: TypeId,
}
pub trait InnerTypes {
fn inner_types() -> Vec<InnerType> {
vec![]
}
}
impl<O, E> InnerTypes for Result<O, E>
where
O: InnerTypes,
E: InnerTypes,
{
fn inner_types() -> Vec<InnerType> {
let mut out = O::inner_types();
out.extend(E::inner_types());
out
}
}
impl<T: InnerTypes> InnerTypes for Vec<T> {
fn inner_types() -> Vec<InnerType> {
T::inner_types()
}
}
impl<const N: usize, T: InnerTypes> InnerTypes for [T; N] {
fn inner_types() -> Vec<InnerType> {
T::inner_types()
}
}
macro_rules! impl_inner {
($ty:ident $($rest:ident)+) => {
impl_inner!($ty);
impl_inner!($($rest)+);
};
($ty:ident) => {
impl InnerTypes for $ty {}
};
}
impl_inner!(bool u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 String Address Bytes);
impl<const B: usize, const L: usize> InnerTypes for Uint<B, L> {}
impl<const B: usize, const L: usize> InnerTypes for Signed<B, L> {}
impl<const N: usize> InnerTypes for FixedBytes<N> {}
macro_rules! impl_tuple {
() => {
impl InnerTypes for () {}
};
($first:ident $(, $rest:ident)*) => {
impl<$first: InnerTypes $(, $rest: InnerTypes)*> InnerTypes for ( $first $(, $rest)* , ) {
fn inner_types() -> Vec<InnerType> {
vec![]
}
}
impl_tuple! { $($rest),* }
};
}
impl_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);