Parse Rust's attribute arguments by defining a struct.
See #[derive(StructMeta)]
documentation for details.
Add this to your Cargo.toml:
toml
[dependencies]
structmeta = "0.2.0"
syn = "2.0.4"
```rust use structmeta::StructMeta; use syn::{parse_quote, Attribute, LitInt, LitStr};
struct MyAttr { x: LitInt, y: LitStr, } let attr: Attribute = parsequote!(#[myattr(x = 10, y = "abc")]); let attr: MyAttr = attr.parse_args().unwrap(); println!("x = {}, y = {}", attr.x, attr.y.value()); ```
This code outputs:
txt
x = 10, y = abc
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
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.