Skip to content

Nested atrribute structs #3

@Techassi

Description

@Techassi

Hey!

Is it possible to create nested attribute structs? I was thinking something like:

use structmeta::StructMeta;
use syn::{Attribute, LitStr};

struct CommonAttrs {
    foo: LitStr,
    bar: LitStr,
}

#[derive(StructMeta)]
struct Attrs {
    common: CommonAttrs,
    baz: LitStr,
}

fn parse(attrs: Vec<Attribute>) {
    for attr in attrs {
        if !attr.path.is_ident("my_macro") {
            continue;
        }

        struct_attrs = attr.parse_args::<Attrs>()?;
    }
}

With the following macro:

#[derive(MyMacro)]
#[my_macro(foo = "foo", bar = "bar", baz = "baz")]
struct Data {}

This would allow one to extract common attributes without maintaining different attribute structs with the same common fields. Let me know if that's possible and, if not, if this is planned for the future. Thx!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions