tier-derive 0.1.17

Derive macros for tier Rust configuration metadata
Documentation
use syn::Attribute;

use super::model::PatchAttrs;
use crate::syntax::{consume_unused_meta, parse_expr_value, parse_string_value};

pub(crate) fn parse_patch_attrs(attributes: &[Attribute]) -> syn::Result<PatchAttrs> {
    let mut attrs = PatchAttrs::default();
    for attribute in attributes {
        if !attribute.path().is_ident("tier") {
            continue;
        }
        attribute.parse_nested_meta(|meta| {
            if meta.path.is_ident("path") {
                attrs.path = Some(parse_string_value(meta)?);
                return Ok(());
            }
            if meta.path.is_ident("path_expr") {
                attrs.path_expr = Some(parse_expr_value(meta)?);
                return Ok(());
            }
            if meta.path.is_ident("nested") {
                attrs.nested = true;
                consume_unused_meta(meta)?;
                return Ok(());
            }
            if meta.path.is_ident("skip") {
                attrs.skip = true;
                consume_unused_meta(meta)?;
                return Ok(());
            }
            Err(meta.error("unsupported tier patch attribute"))
        })?;
    }
    Ok(attrs)
}