48 lines
2.2 KiB
Markdown
48 lines
2.2 KiB
Markdown
# Bind9 configuration parsing library
|
|
|
|
## `Parse` derive macro
|
|
|
|
The `Parse` derive macro can ease a lot `Parse` trait implementation on common types and prevents a lot of boilerplate code.
|
|
|
|
### Attributes
|
|
|
|
Attributes can allow better configuration of the way the types should be parsed. They can be used as follow:
|
|
|
|
```rust
|
|
#[derive(Parse)]
|
|
#[parse(global_attr = "my value")]
|
|
struct MyStruct {
|
|
|
|
#[parse(struct_attr)]
|
|
my_property: String
|
|
}
|
|
```
|
|
|
|
#### Global
|
|
|
|
Those attributes can be applied directly on type definition.
|
|
|
|
* `path = "path::to::bind_conf"` specifies the path to this crate, default to `bind_conf` but can be useful in case of reexport.
|
|
|
|
* `fallback = "Variant"` used with when `enum`, specifies a fallback variant when a unknown key is encountered, preventing the `UnknownVariant` error.
|
|
|
|
#### Structures
|
|
|
|
Those attributes can be applied on structure properties.
|
|
|
|
* `rename = "my-other-name"` default renaming rules change Rust snake case for kebab case, this is useful when you need a totally different name, for example to avoid conflicting with some reserved key words.
|
|
|
|
* `alias = "my-alias"` used when a statement can have different names, note that it can be used more than once, for example `parse(alias = "my-alias", alias = "other-alias")` will cause the property to match both `my-alias` and `other-alias` as well as its normal name. Can be combined with `rename`.
|
|
|
|
* `inline` flag to indicate that the statement will be inline.
|
|
|
|
* `default = "path::to::a_function"` use the defined function to get the property value if it was missing, the function must have no arguments, works for inline and block statements.
|
|
|
|
#### Enumerations
|
|
|
|
Those attributes can be applied on enumeration variants.
|
|
|
|
* `rename = "my-other-name"` default renaming rules change Rust snake case for kebab case, this is useful when you need a totally different name, for example to avoid conflicting with some reserved key words.
|
|
|
|
* `alias = "my-alias"` used when a statement can have different names, note that it can be used more than once, for example `parse(alias = "my-alias", alias = "other-alias")` will cause the property to match both `my-alias` and `other-alias` as well as its normal name. Can be combined with `rename`.
|