Skip to content

Commit

Permalink
Move cfg attrs collection in a dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfariello authored and tikue committed Feb 12, 2024
1 parent 6fdfbc6 commit db276ea
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ pub fn derive_serde(_attr: TokenStream, item: TokenStream) -> TokenStream {
proc_macro::TokenStream::from(gen)
}

fn collect_cfg_attrs(rpcs: &[RpcMethod]) -> Vec<Vec<&Attribute>> {
rpcs.iter()
.map(|rpc| {
rpc.attrs
.iter()
.filter(|att| {
att.style == AttrStyle::Outer
&& match &att.meta {
syn::Meta::List(syn::MetaList { path, .. }) => {
path.get_ident() == Some(&Ident::new("cfg", rpc.ident.span()))
}
_ => false,
}
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
}

/// Generates:
/// - service trait
/// - serve fn
Expand Down Expand Up @@ -289,23 +308,7 @@ pub fn service(attr: TokenStream, input: TokenStream) -> TokenStream {
vis,
args,
method_attrs: &rpcs.iter().map(|rpc| &*rpc.attrs).collect::<Vec<_>>(),
method_cfgs: &rpcs
.iter()
.map(|rpc| {
rpc.attrs
.iter()
.filter(|att| {
att.style == AttrStyle::Outer
&& match &att.meta {
syn::Meta::List(syn::MetaList { path, .. }) => {
path.get_ident() == Some(&Ident::new("cfg", rpc.ident.span()))
}
_ => false,
}
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>(),
method_cfgs: &collect_cfg_attrs(rpcs),
method_idents: &methods,
request_names: &request_names,
attrs,
Expand Down

0 comments on commit db276ea

Please sign in to comment.