How to produce syn::Meta?

241 Views Asked by At

I am "parsing" AST (namely, DeriveInput) produced by parse_macro_input!(input as DeriveInput) in my derive macros implementation.

I found a useful for my purposes type, enum syn::Meta.

It is, however, unclear how I construct the appropriate value of syn::Meta for a field of a struct that I apply attributes to: syn::Field::Attrs contains attrs: Vec<Attribute> where Attribute contains tokens: TokenStream (that are inconvenient to deal with) instead of expected syn::Meta.

Maybe, I should convert Vec<Attribute> to or TokenStream to syn::Meta? How to do this?

1

There are 1 best solutions below

0
porton On

I've found (have searched for functions returning Meta):

Here:

pub fn parse_meta(&self) -> Result<Meta>

Available on crate feature parsing only.

Parses the content of the attribute, consisting of the path and tokens, as a Meta if possible.

This function is available only if Syn is built with the "parsing" feature.)