Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions stylus-proc/src/macros/derive/solidity_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ impl DeriveSolidityError {
}
}
}

fn method_error_impl(&self) -> syn::ItemImpl {
let name = &self.name;
parse_quote! {
impl stylus_sdk::stylus_core::errors::MethodError for #name {
fn encode(self) -> alloc::vec::Vec<u8> {
self.into()
}
}
}
}
}

impl From<&syn::ItemEnum> for DeriveSolidityError {
Expand Down Expand Up @@ -101,6 +112,7 @@ impl ToTokens for DeriveSolidityError {
from_impl.to_tokens(tokens);
}
self.vec_u8_from_impl().to_tokens(tokens);
self.method_error_impl().to_tokens(tokens);
Extension::codegen(self).to_tokens(tokens);
}
}
Expand Down Expand Up @@ -160,5 +172,13 @@ mod tests {
}
},
);
assert_ast_eq(
derived.method_error_impl(),
parse_quote!{
impl stylus_sdk::stylus_core::errors::MethodError for MyError {
fn encode(self) -> alloc::vec::Vec<u8> { self.into() }
}
}
)
}
}