Function proc_macro_roids::namespace_parameter
source · pub fn namespace_parameter(
attrs: &[Attribute],
namespace: &Path
) -> Option<Meta>
Expand description
Returns the parameter from #[namespace(parameter)]
.
Parameters
attrs
: Attributes of the item to inspect.namespace
: Thepath()
of the first-level attribute.
Examples
ⓘ
use proc_macro_roids::namespace_parameter;
use syn::{parse_quote, DeriveInput, Meta, Path};
let ast: DeriveInput = parse_quote! {
#[namespace(One)]
pub struct MyEnum;
};
let ns: Path = parse_quote!(namespace);
let namespace_param = namespace_parameter(&ast.attrs, &ns);
let meta_one: Path = parse_quote!(One);
let param_one = Meta::Path(meta_one);
assert_eq!(Some(param_one), namespace_param);
let ns_other: Path = parse_quote!(namespace_other);
let namespace_param_other = namespace_parameter(&ast.attrs, &ns_other);
assert_eq!(None, namespace_param_other);
Panics
Panics if the number of parameters for the tag is not exactly one.