Skip to content

Parse Rust's attribute by defining a struct.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

tsurucapital/structmeta

 
 

Repository files navigation

StructMeta

Crates.io Docs.rs Actions Status

Parse Rust's attribute arguments by defining a struct.

Documentation

See #[derive(StructMeta)] documentation for details.

Example

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

#[derive(StructMeta, Debug)]
struct MyAttr {
    x: LitInt,
    y: LitStr,
}
let attr: Attribute = parse_quote!(#[my_attr(x = 10, y = "abc")]);
let attr: MyAttr = attr.parse_args().unwrap();
println!("x = {}, y = {}", attr.x, attr.y.value());

This code outputs:

x = 10, y = abc

License

This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Parse Rust's attribute by defining a struct.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%