|
1 | 1 | # attribute-derive
|
2 | 2 |
|
3 |
| -You will be able to find the documentation on docs.rs. |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +Basicly clap for attribute macros: |
| 8 | +```rust |
| 9 | +#[derive(Attribute)] |
| 10 | +#[attribute(ident = "collection")] |
| 11 | +#[attribute(invalid_field = "Error when an unsupported value is set (e.g. meaning=42")] |
| 12 | +struct CollectionAttribute { |
| 13 | + // Options are optional by default (will be set to None if not specified) |
| 14 | + authority: Option<String>, |
| 15 | + #[attribute(missing = "Error when the value is not set")] |
| 16 | + name: String, |
| 17 | + // Any type implementing default can be flagged as default |
| 18 | + // This will be set to Vec::default() when not specified |
| 19 | + #[attribute(default)] |
| 20 | + #[attribute(expected = "Error when an error occured while parsing")] |
| 21 | + views: Vec<Type>, |
| 22 | + // Booleans can be used without assiging a value. as a flag. |
| 23 | + // If omitted they are set to false |
| 24 | + some_flag |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +Will be able to parse an attribute like this: |
| 29 | +```rust |
| 30 | +#[collection(authority="Some String", name = r#"Another string"#, views = [Option, ()])] |
| 31 | +``` |
| 32 | + |
| 33 | +## Limitations |
| 34 | + |
| 35 | +There are some limitations in syntax parsing that will be lifted future releases. |
| 36 | + |
| 37 | +- literals in top level (meaning something like `#[attr(42, 3.14, "hi")]` |
| 38 | +- function like arguments (something like `#[attr(view(a = "test"))]` |
| 39 | +- other syntaxes, maybe something like `key: value` |
0 commit comments