File: README.md

package info (click to toggle)
rust-structmeta 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# StructMeta

[![Crates.io](https://img.shields.io/crates/v/structmeta.svg)](https://crates.io/crates/structmeta)
[![Docs.rs](https://docs.rs/structmeta/badge.svg)](https://docs.rs/structmeta/)
[![Actions Status](https://github.com/frozenlib/structmeta/workflows/CI/badge.svg)](https://github.com/frozenlib/structmeta/actions)

Parse Rust's attribute arguments by defining a struct.

## Documentation

See [`#[derive(StructMeta)]` documentation](https://docs.rs/structmeta/latest/structmeta/derive.StructMeta.html) for details.

## Install

Add this to your Cargo.toml:

```toml
[dependencies]
structmeta = "0.2.0"
syn = "2.0.4"
```

## Example

```rust
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:

```txt
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.