Skip to content

Commit

Permalink
chore(sol-macro): tweak inline attributes in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Jan 28, 2024
1 parent d9679f4 commit ad39885
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/sol-macro/src/expand/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,17 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result<TokenS
const SIGNATURE: &'static str = #signature;
const SELECTOR: [u8; 4] = #selector;

#[inline]
fn new<'a>(tuple: <Self::Parameters<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
tuple.into()
}

#[inline]
fn tokenize(&self) -> Self::Token<'_> {
#tokenize_impl
}

#[inline]
fn abi_decode_returns(data: &[u8], validate: bool) -> ::alloy_sol_types::Result<Self::Return> {
<Self::ReturnTuple<'_> as ::alloy_sol_types::SolType>::abi_decode_sequence(data, validate).map(Into::into)
}
Expand Down Expand Up @@ -186,10 +189,12 @@ fn expand_constructor(cx: &ExpCtxt<'_>, constructor: &ItemFunction) -> Result<To
type Parameters<'a> = #call_tuple;
type Token<'a> = <Self::Parameters<'a> as ::alloy_sol_types::SolType>::Token<'a>;

#[inline]
fn new<'a>(tuple: <Self::Parameters<'a> as ::alloy_sol_types::SolType>::RustType) -> Self {
tuple.into()
}

#[inline]
fn tokenize(&self) -> Self::Token<'_> {
#tokenize_impl
}
Expand Down
3 changes: 3 additions & 0 deletions crates/sol-macro/src/expand/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, s: &ItemStruct) -> Result<TokenStream> {

#[automatically_derived]
impl ::alloy_sol_types::private::SolTypeValue<Self> for #name {
#[inline]
fn stv_to_tokens(&self) -> <Self as ::alloy_sol_types::SolType>::Token<'_> {
#tokenize_impl
}
Expand Down Expand Up @@ -134,6 +135,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, s: &ItemStruct) -> Result<TokenStream> {

#eip712_encode_type_fns

#[inline]
fn eip712_encode_data(&self) -> ::alloy_sol_types::private::Vec<u8> {
#encode_data_impl
}
Expand Down Expand Up @@ -238,6 +240,7 @@ fn expand_encode_type_fns(
::alloy_sol_types::private::Cow::Borrowed(#root)
}

#[inline]
fn eip712_components() -> ::alloy_sol_types::private::Vec<::alloy_sol_types::private::Cow<'static, str>> {
#components_impl
}
Expand Down
1 change: 1 addition & 0 deletions crates/sol-types/src/types/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub trait SolType: Sized {
/// Tokenizes the given value into this type's token.
///
/// See the [`abi::token`] module for more information.
#[inline]
fn tokenize<E: ?Sized + SolTypeValue<Self>>(rust: &E) -> Self::Token<'_> {
rust.stv_to_tokens()
}
Expand Down

0 comments on commit ad39885

Please sign in to comment.