pub fn namespace_parameters(attrs: &[Attribute], namespace: &Path) -> Vec<Meta>
Expand description

Returns the parameters from #[namespace(param1, param2, ..)].

Parameters

  • attrs: Attributes of the item to inspect.
  • namespace: The path() of the first-level attribute.

Examples

use proc_macro_roids::namespace_parameters;
use syn::{parse_quote, DeriveInput, Lit, LitStr, Meta, MetaNameValue, Path};

let ast: DeriveInput = parse_quote! {
    #[namespace(One, two = "")]
    #[namespace(three(Value))]
    pub struct MyEnum;
};

let ns: Path = parse_quote!(namespace);
let namespace_parameters = namespace_parameters(&ast.attrs, &ns);

let meta_one: Path = parse_quote!(One);
let param_one = Meta::Path(meta_one);
let meta_two: MetaNameValue = parse_quote!(two = "");
let param_two = Meta::NameValue(meta_two);
let meta_three: LitStr = parse_quote!("three");
let param_three = Meta::List(parse_quote!(three(Value)));
assert_eq!(
    vec![param_one, param_two, param_three],
    namespace_parameters
);