Dedup private account module re-exports

This commit is contained in:
Armani Ferrante 2021-01-30 02:16:51 -08:00
parent 53e0a58648
commit 5787cec1fa
No known key found for this signature in database
GPG Key ID: D597A80BCF8E12B7
1 changed files with 19 additions and 15 deletions

View File

@ -204,26 +204,30 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
// structs are *not* visible from the #[program] macro, which is responsible
// for generating the `accounts` mod, which aggregates all the the generated
// accounts used for structs.
let re_exports: Vec<proc_macro2::TokenStream> = accs
.fields
.iter()
.filter_map(|f: &AccountField| match f {
let re_exports: Vec<proc_macro2::TokenStream> = {
// First, dedup the exports.
let mut re_exports = std::collections::HashSet::new();
for f in accs.fields.iter().filter_map(|f: &AccountField| match f {
AccountField::AccountsStruct(s) => Some(s),
AccountField::Field(_) => None,
})
.map(|f: &CompositeField| {
let symbol: proc_macro2::TokenStream = format!(
}) {
re_exports.insert(format!(
"__client_accounts_{0}::{1}",
f.symbol.to_snake_case(),
f.symbol,
)
.parse()
.unwrap();
quote! {
pub use #symbol;
}
})
.collect();
));
}
re_exports
.iter()
.map(|symbol: &String| {
let symbol: proc_macro2::TokenStream = symbol.parse().unwrap();
quote! {
pub use #symbol;
}
})
.collect()
};
quote! {