syn: Rename derive related modules anchor -> accounts
This commit is contained in:
parent
8caee03251
commit
7f02eb13af
|
@ -1,13 +1,13 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
use anchor_syn::codegen::anchor as anchor_codegen;
|
||||
use anchor_syn::parser::anchor as anchor_parser;
|
||||
use anchor_syn::codegen::accounts as accounts_codegen;
|
||||
use anchor_syn::parser::accounts as accounts_parser;
|
||||
use proc_macro::TokenStream;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
#[proc_macro_derive(Accounts, attributes(account))]
|
||||
pub fn derive_anchor_deserialize(item: TokenStream) -> TokenStream {
|
||||
let strct = parse_macro_input!(item as syn::ItemStruct);
|
||||
let tts = anchor_codegen::generate(anchor_parser::parse(&strct));
|
||||
let tts = accounts_codegen::generate(accounts_parser::parse(&strct));
|
||||
proc_macro::TokenStream::from(tts)
|
||||
}
|
||||
|
|
|
@ -12,5 +12,4 @@ name = "basic_0"
|
|||
borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
|
||||
solana-program = "1.4.3"
|
||||
solana-sdk = { version = "1.3.14", default-features = false, features = ["program"] }
|
||||
# anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { path = "/home/armaniferrante/Documents/code/src/github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
|
|
|
@ -12,5 +12,4 @@ name = "basic_1"
|
|||
borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
|
||||
solana-program = "1.4.3"
|
||||
solana-sdk = { version = "1.3.14", default-features = false, features = ["program"] }
|
||||
# anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { path = "/home/armaniferrante/Documents/code/src/github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
|
|
|
@ -12,5 +12,4 @@ name = "basic_2"
|
|||
borsh = { git = "https://github.com/project-serum/borsh", branch = "serum", features = ["serum-program"] }
|
||||
solana-program = "1.4.3"
|
||||
solana-sdk = { version = "1.3.14", default-features = false, features = ["program"] }
|
||||
# anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { path = "/home/armaniferrante/Documents/code/src/github.com/project-serum/anchor", features = ["derive"] }
|
||||
anchor = { git = "https://github.com/project-serum/anchor", features = ["derive"] }
|
||||
|
|
|
@ -61,16 +61,12 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
|
|||
|
||||
let name = &accs.ident;
|
||||
let (combined_generics, trait_generics, strct_generics) = match accs.generics.lt_token {
|
||||
None => (
|
||||
quote!{<'info>},
|
||||
quote!{<'info>},
|
||||
quote!{},
|
||||
),
|
||||
Some(_) => {
|
||||
let g = &accs.generics;
|
||||
(quote!{#g}, quote!{#g}, quote!{#g})
|
||||
}
|
||||
};
|
||||
None => (quote! {<'info>}, quote! {<'info>}, quote! {}),
|
||||
Some(_) => {
|
||||
let g = &accs.generics;
|
||||
(quote! {#g}, quote! {#g}, quote! {#g})
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
impl#combined_generics Accounts#trait_generics for #name#strct_generics {
|
|
@ -1,2 +1,2 @@
|
|||
pub mod anchor;
|
||||
pub mod accounts;
|
||||
pub mod program;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::idl::*;
|
||||
use crate::parser::anchor;
|
||||
use crate::parser::accounts;
|
||||
use crate::parser::program;
|
||||
use crate::AccountsStruct;
|
||||
use anyhow::Result;
|
||||
|
@ -133,7 +133,7 @@ fn parse_accounts(f: &syn::File) -> HashMap<String, AccountsStruct> {
|
|||
syn::Item::Struct(i_strct) => {
|
||||
for attr in &i_strct.attrs {
|
||||
if attr.tokens.to_string().contains(DERIVE_NAME) {
|
||||
let strct = anchor::parse(i_strct);
|
||||
let strct = accounts::parse(i_strct);
|
||||
return Some((strct.ident.to_string(), strct));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub mod anchor;
|
||||
pub mod accounts;
|
||||
#[cfg(feature = "idl")]
|
||||
pub mod file;
|
||||
pub mod program;
|
||||
|
|
Loading…
Reference in New Issue