pub fn tag_parameter(
    attrs: &[Attribute],
    namespace: &Path,
    tag: &Path
) -> Option<Meta>
Expand description

Returns the parameter from #[namespace(tag(parameter))].

Parameters

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

Examples

use proc_macro_roids::tag_parameter;
use syn::{parse_quote, DeriveInput, Meta, Path};

let ast: DeriveInput = parse_quote! {
    #[namespace(tag(One))]
    pub struct MyEnum;
};

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

let meta_one: Path = parse_quote!(One);
let param_one = Meta::Path(meta_one);
assert_eq!(Some(param_one), tag_param);

let tag_other: Path = parse_quote!(tag_other);
let tag_param_other = tag_parameter(&ast.attrs, &ns, &tag_other);
assert_eq!(None, tag_param_other);

Panics

Panics if the number of parameters for the tag is not exactly one.