diff --git a/crates/dyn-abi/src/resolve.rs b/crates/dyn-abi/src/resolve.rs index e6eb2eacfe..f9085c7f61 100644 --- a/crates/dyn-abi/src/resolve.rs +++ b/crates/dyn-abi/src/resolve.rs @@ -41,49 +41,13 @@ pub trait ResolveSolType { } impl ResolveSolType for str { + #[inline] fn resolve(&self) -> DynAbiResult { - TypeSpecifier::try_from(self)?.resolve() - } -} - -impl ResolveSolType for &T -where - T: ResolveSolType, -{ - fn resolve(&self) -> DynAbiResult { - (**self).resolve() - } -} - -impl ResolveSolType for &mut T -where - T: ResolveSolType, -{ - fn resolve(&self) -> DynAbiResult { - (**self).resolve() - } -} - -impl ResolveSolType for alloc::boxed::Box -where - T: ResolveSolType, -{ - fn resolve(&self) -> DynAbiResult { - (**self).resolve() - } -} - -impl ResolveSolType for alloc::sync::Arc -where - T: ResolveSolType, -{ - fn resolve(&self) -> DynAbiResult { - (**self).resolve() + TypeSpecifier::parse(self)?.resolve() } } impl ResolveSolType for RootType<'_> { - /// Resolve the type string into a basic Solidity type. fn resolve(&self) -> DynAbiResult { match self.span() { "address" => Ok(DynSolType::Address), @@ -152,8 +116,9 @@ impl ResolveSolType for TypeStem<'_> { impl ResolveSolType for TypeSpecifier<'_> { #[inline] fn resolve(&self) -> Result { - let ty = self.stem.resolve()?; - Ok(ty.array_wrap_from_iter(self.sizes.iter().copied())) + self.stem + .resolve() + .map(|ty| ty.array_wrap_from_iter(self.sizes.iter().copied())) } } @@ -225,6 +190,28 @@ impl ResolveSolType for EventParam { } } +macro_rules! deref_impl { + ($($(#[$attr:meta])* [$($gen:tt)*] $t:ty),+ $(,)?) => {$( + $(#[$attr])* + impl<$($gen)*> ResolveSolType for $t { + #[inline] + fn resolve(&self) -> DynAbiResult { + (**self).resolve() + } + } + )+}; +} + +deref_impl! { + [] alloc::string::String, + [T: ?Sized + ResolveSolType] &T, + [T: ?Sized + ResolveSolType] &mut T, + [T: ?Sized + ResolveSolType] alloc::boxed::Box, + [T: ?Sized + alloc::borrow::ToOwned + ResolveSolType] alloc::borrow::Cow<'_, T>, + [T: ?Sized + ResolveSolType] alloc::rc::Rc, + [T: ?Sized + ResolveSolType] alloc::sync::Arc, +} + #[cfg(test)] mod tests { use super::*;