-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple derive macro for better struct support
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, ItemStruct}; | ||
|
||
pub fn derive_abi_type(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as ItemStruct); | ||
let name = &input.ident; | ||
let name_str = name.to_string(); | ||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); | ||
|
||
quote! { | ||
impl #impl_generics stylus_sdk::abi::AbiType for #name #ty_generics #where_clause { | ||
type SolType = Self; | ||
const ABI: stylus_sdk::abi::ConstString = stylus_sdk::abi::ConstString::new(#name_str); | ||
} | ||
} | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters