pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
    let name = &accs.ident;
    let ParsedGenerics {
        combined_generics,
        trait_generics,
        struct_generics,
        where_clause,
    } = generics(accs);

    // Deserialization for each field
    let deser_fields: Vec<proc_macro2::TokenStream> = accs
        .fields
        .iter()
        .map(|af: &AccountField| {
            match af {
                AccountField::CompositeField(s) => {
                    let name = &s.ident;
                    let ty = &s.raw_field.ty;
                    quote! {
                        #[cfg(feature = "anchor-debug")]
                        ::solana_program::log::sol_log(stringify!(#name));
                        let #name: #ty = anchor_lang::Accounts::try_accounts(program_id, accounts, ix_data)?;
                    }
                }
                AccountField::Field(f) => {
                    // Associated fields are *first* deserialized into
                    // AccountInfos, and then later deserialized into
                    // ProgramAccounts in the "constraint check" phase.
                    if is_pda_init(af) {
                        let name = &f.ident;
                        quote!{
                            let #name = &accounts[0];
                            *accounts = &accounts[1..];
                        }
                    } else {
                        let name = typed_ident(f);
                        match f.constraints.is_init() {
                            false => quote! {
                                #[cfg(feature = "anchor-debug")]
                                ::solana_program::log::sol_log(stringify!(#name));
                                let #name = anchor_lang::Accounts::try_accounts(program_id, accounts, ix_data)?;
                            },
                            true => quote! {
                                #[cfg(feature = "anchor-debug")]
                                ::solana_program::log::sol_log(stringify!(#name));
                                let #name = anchor_lang::AccountsInit::try_accounts_init(program_id, accounts)?;
                            },
                        }
                    }
                }
            }
        })
        .collect();

    let constraints = generate_constraints(accs);
    let accounts_instance = generate_accounts_instance(accs);

    let ix_de = match &accs.instruction_api {
        None => quote! {},
        Some(ix_api) => {
            let strct_inner = &ix_api;
            let field_names: Vec<proc_macro2::TokenStream> = ix_api
                .iter()
                .map(|expr: &Expr| match expr {
                    Expr::Type(expr_type) => {
                        let field = &expr_type.expr;
                        quote! {
                            #field
                        }
                    }
                    _ => panic!("Invalid instruction declaration"),
                })
                .collect();
            quote! {
                let mut ix_data = ix_data;
                #[derive(anchor_lang::AnchorSerialize, anchor_lang::AnchorDeserialize)]
                struct __Args {
                    #strct_inner
                }
                let __Args {
                    #(#field_names),*
                } = __Args::deserialize(&mut ix_data)
                    .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
            }
        }
    };

    quote! {
        #[automatically_derived]
        impl<#combined_generics> anchor_lang::Accounts<#trait_generics> for #name<#struct_generics> #where_clause {
            #[inline(never)]
            fn try_accounts(
                program_id: &anchor_lang::solana_program::pubkey::Pubkey,
                accounts: &mut &[anchor_lang::solana_program::account_info::AccountInfo<'info>],
                ix_data: &[u8],
            ) -> std::result::Result<Self, anchor_lang::solana_program::program_error::ProgramError> {
                // Deserialize instruction, if declared.
                #ix_de
                // Deserialize each account.
                #(#deser_fields)*
                // Execute accounts constraints.
                #constraints
                // Success. Return the validated accounts.
                Ok(#accounts_instance)
            }
        }
    }
}
// Generates the `Accounts` trait implementation.
Generates the `Accounts` trait implementation.
Generates the ` Accounts ` trait implementation .
pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
    let name = &accs.ident;
    let ParsedGenerics {
        combined_generics,
        trait_generics,
        struct_generics,
        where_clause,
    } = generics(accs);
    // Deserialization for each field
    let deser_fields: Vec<proc_macro2::TokenStream> = accs
        .fields
        .iter()
        .map(|af: &AccountField| {
            match af {
                AccountField::CompositeField(s) => {
                    let name = &s.ident;
                    let ty = &s.raw_field.ty;
                    quote! {
                        #[cfg(feature = "anchor-debug")]
                        ::solana_program::log::sol_log(stringify!(#name));
                        let #name: #ty = anchor_lang::Accounts::try_accounts(program_id, accounts, ix_data)?;
                    }
                }
                AccountField::Field(f) => {
                    // Associated fields are *first* deserialized into
                    // AccountInfos, and then later deserialized into
                    // ProgramAccounts in the "constraint check" phase.
                    if is_pda_init(af) {
                        let name = &f.ident;
                        quote!{
                            let #name = &accounts[0];
                            *accounts = &accounts[1..];
                        }
                    } else {
                        let name = typed_ident(f);
                        match f.constraints.is_init() {
                            false => quote! {
                                #[cfg(feature = "anchor-debug")]
                                ::solana_program::log::sol_log(stringify!(#name));
                                let #name = anchor_lang::Accounts::try_accounts(program_id, accounts, ix_data)?;
                            },
                            true => quote! {
                                #[cfg(feature = "anchor-debug")]
                                ::solana_program::log::sol_log(stringify!(#name));
                                let #name = anchor_lang::AccountsInit::try_accounts_init(program_id, accounts)?;
                            },
                        }
                    }
                }
            }
        })
        .collect();
    let constraints = generate_constraints(accs);
    let accounts_instance = generate_accounts_instance(accs);
    let ix_de = match &accs.instruction_api {
        None => quote! {},
        Some(ix_api) => {
            let strct_inner = &ix_api;
            let field_names: Vec<proc_macro2::TokenStream> = ix_api
                .iter()
                .map(|expr: &Expr| match expr {
                    Expr::Type(expr_type) => {
                        let field = &expr_type.expr;
                        quote! {
                            #field
                        }
                    }
                    _ => panic!("Invalid instruction declaration"),
                })
                .collect();
            quote! {
                let mut ix_data = ix_data;
                #[derive(anchor_lang::AnchorSerialize, anchor_lang::AnchorDeserialize)]
                struct __Args {
                    #strct_inner
                }
                let __Args {
                    #(#field_names),*
                } = __Args::deserialize(&mut ix_data)
                    .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
            }
        }
    };
    quote! {
        #[automatically_derived]
        impl<#combined_generics> anchor_lang::Accounts<#trait_generics> for #name<#struct_generics> #where_clause {
            #[inline(never)]
            fn try_accounts(
                program_id: &anchor_lang::solana_program::pubkey::Pubkey,
                accounts: &mut &[anchor_lang::solana_program::account_info::AccountInfo<'info>],
                ix_data: &[u8],
            ) -> std::result::Result<Self, anchor_lang::solana_program::program_error::ProgramError> {
                // Deserialize instruction, if declared.
                #ix_de
                // Deserialize each account.
                #(#deser_fields)*
                // Execute accounts constraints.
                #constraints
                // Success. Return the validated accounts.
                Ok(#accounts_instance)
            }
        }
    }
}
pub fn generate ( accs : & AccountsStruct ) -> proc_macro2 :: TokenStream { let name = & accs . ident ; let ParsedGenerics { combined_generics , trait_generics , struct_generics , where_clause , } = generics ( accs ) ; // Deserialization for each field let deser_fields : Vec < proc_macro2 :: TokenStream > = accs . fields . iter ( ) . map ( | af : & AccountField | { match af { AccountField :: CompositeField ( s ) => { let name = & s . ident ; let ty = & s . raw_field . ty ; quote ! { [ cfg ( feature " " ) ] solana_program log sol_log ( stringify ( name ) ) let name ty anchor_lang Accounts try_accounts ( program_id accounts ix_data ) } } AccountField :: Field ( f ) => { // Associated fields are *first* deserialized into // AccountInfos, and then later deserialized into // ProgramAccounts in the "constraint check" phase. if is_pda_init ( af ) { let name = & f . ident ; quote ! { let name accounts [ 0 ] accounts accounts [ 1 ] } } else { let name = typed_ident ( f ) ; match f . constraints . is_init ( ) { false => quote ! { [ cfg ( feature " " ) ] solana_program log sol_log ( stringify ( name ) ) let name anchor_lang Accounts try_accounts ( program_id accounts ix_data ) } , true => quote ! { [ cfg ( feature " " ) ] solana_program log sol_log ( stringify ( name ) ) let name anchor_lang AccountsInit try_accounts_init ( program_id accounts ) } , } } } } } ) . collect ( ) ; let constraints = generate_constraints ( accs ) ; let accounts_instance = generate_accounts_instance ( accs ) ; let ix_de = match & accs . instruction_api { None => quote ! { } , Some ( ix_api ) => { let strct_inner = & ix_api ; let field_names : Vec < proc_macro2 :: TokenStream > = ix_api . iter ( ) . map ( | expr : & Expr | match expr { Expr :: Type ( expr_type ) => { let field = & expr_type . expr ; quote ! { field } } _ => panic ! ( " " ) , } ) . collect ( ) ; quote ! { let mut ix_data ix_data [ derive ( anchor_lang AnchorSerialize anchor_lang AnchorDeserialize ) ] struct __Args { strct_inner } let __Args { ( field_names ) } __Args deserialize ( mut ix_data ) map_err ( anchor_lang private ErrorCode InstructionDidNotDeserialize ) } } } ; quote ! { [ automatically_derived ] impl combined_generics anchor_lang Accounts trait_generics for name struct_generics where_clause { [ inline ( never ) ] fn try_accounts ( program_id anchor_lang solana_program pubkey Pubkey accounts mut [ anchor_lang solana_program account_info AccountInfo ' info ] ix_data [ u8 ] ) std result Result Self anchor_lang solana_program program_error ProgramError { // Deserialize instruction, if declared. ix_de // Deserialize each account. ( deser_fields ) // Execute accounts constraints. constraints // Success. Return the validated accounts. Ok ( accounts_instance ) } } } }
Generates the `Accounts` trait implementation.
Generates the ` Accounts ` trait implementation .
accs
&AccountsStruct