lang: repr override for zero copy (#1273)
This commit is contained in:
parent
e3d733c996
commit
d7e72b33d1
|
@ -291,9 +291,21 @@ pub fn zero_copy(
|
||||||
) -> proc_macro::TokenStream {
|
) -> proc_macro::TokenStream {
|
||||||
let account_strct = parse_macro_input!(item as syn::ItemStruct);
|
let account_strct = parse_macro_input!(item as syn::ItemStruct);
|
||||||
|
|
||||||
|
// Takes the first repr. It's assumed that more than one are not on the
|
||||||
|
// struct.
|
||||||
|
let attr = account_strct
|
||||||
|
.attrs
|
||||||
|
.iter()
|
||||||
|
.find(|attr| anchor_syn::parser::tts_to_string(&attr.path) == "repr");
|
||||||
|
|
||||||
|
let repr = match attr {
|
||||||
|
Some(_attr) => quote! {},
|
||||||
|
None => quote! {#[repr(C)]},
|
||||||
|
};
|
||||||
|
|
||||||
proc_macro::TokenStream::from(quote! {
|
proc_macro::TokenStream::from(quote! {
|
||||||
#[derive(anchor_lang::__private::ZeroCopyAccessor, Copy, Clone)]
|
#[derive(anchor_lang::__private::ZeroCopyAccessor, Copy, Clone)]
|
||||||
#[repr(C)]
|
#repr
|
||||||
#account_strct
|
#account_strct
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,7 @@ pub struct UpdateLargeAccount<'info> {
|
||||||
|
|
||||||
#[account(zero_copy)]
|
#[account(zero_copy)]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
#[repr(packed)]
|
||||||
pub struct Foo {
|
pub struct Foo {
|
||||||
pub authority: Pubkey,
|
pub authority: Pubkey,
|
||||||
pub data: u64,
|
pub data: u64,
|
||||||
|
|
Loading…
Reference in New Issue