mokuya 0.0.3

Generic procedural macro helpers for parsing, type analysis, and derive macro generation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
use syn::{Attribute, parse::Parse};

pub fn get_attr<T: Parse>(attributes: &[Attribute], name: &str) -> Result<T, String> {
    attributes
        .iter()
        .find(|attr| attr.path().is_ident(name))
        .map_or(Err(format!("Attribute {} not found", name)), |attr| {
            attr.parse_args::<T>()
                .map_err(|_| format!("Failed to parse attribute {}", name))
        })
}