add README description
This commit is contained in:
parent
babd99d24c
commit
3ad76d1c00
46
README.md
46
README.md
@ -1,3 +1,45 @@
|
||||
# lib-rs
|
||||
# macroconf
|
||||
|
||||
Template for rust libraries
|
||||
This library provides a macro to create configs with metadata attached to the values.
|
||||
The [miniconf](https://github.com/quartiq/miniconf) library is used to make the metadata and the values accessible.
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use miniconf::Tree;
|
||||
use macroconf::config;
|
||||
|
||||
#[config]
|
||||
#[derive(Tree)]
|
||||
struct Config {
|
||||
ordinary: i32,
|
||||
|
||||
#[min = 10]
|
||||
#[max = 20]
|
||||
clamped: u8
|
||||
|
||||
#[default = 42]
|
||||
has_default: i32;
|
||||
|
||||
/// Doc comments are used as description
|
||||
with_description: i32
|
||||
}
|
||||
|
||||
/* The resulting miniconf tree looks like this:
|
||||
* /
|
||||
* |-ordinary
|
||||
* |
|
||||
* |-clamped
|
||||
* | |-value
|
||||
* | |-min
|
||||
* | |-max
|
||||
* |
|
||||
* |-has_default
|
||||
* | |-value
|
||||
* | |-default
|
||||
* |
|
||||
* |-with_description
|
||||
* |-value
|
||||
* |-description
|
||||
*/
|
||||
```
|
||||
|
@ -62,7 +62,6 @@ fn generate_helper_struct(
|
||||
let mut new_type_miniconf_names = vec![];
|
||||
let mut new_type_miniconf_consts = vec![];
|
||||
let mut extra_new_checks = TokenStream2::new();
|
||||
let mut generate_new_type = false;
|
||||
for attr in &field.attrs {
|
||||
if let Some((new_type_impl, new_check, const_ident, key)) =
|
||||
parse_min(&new_type_ident, attr, &ty)
|
||||
@ -71,7 +70,6 @@ fn generate_helper_struct(
|
||||
new_type_miniconf_consts.push(const_ident);
|
||||
new_type_miniconf_names.push(key);
|
||||
extra_new_checks.extend(new_check);
|
||||
generate_new_type = true;
|
||||
}
|
||||
if let Some((new_type_impl, new_check, const_ident, key)) =
|
||||
parse_max(&new_type_ident, attr, &ty)
|
||||
@ -80,13 +78,11 @@ fn generate_helper_struct(
|
||||
new_type_miniconf_consts.push(const_ident);
|
||||
new_type_miniconf_names.push(key);
|
||||
extra_new_checks.extend(new_check);
|
||||
generate_new_type = true;
|
||||
}
|
||||
if let Some((new_type_impl, const_ident, key)) = parse_default(&new_type_ident, attr, &ty) {
|
||||
new_type_impls.extend(new_type_impl);
|
||||
new_type_miniconf_consts.push(const_ident);
|
||||
new_type_miniconf_names.push(key);
|
||||
generate_new_type = true;
|
||||
}
|
||||
if let Some((new_type_impl, const_ident, key)) = parse_description(&new_type_ident, attr) {
|
||||
new_type_impls.extend(new_type_impl);
|
||||
@ -94,7 +90,7 @@ fn generate_helper_struct(
|
||||
new_type_miniconf_names.push(key);
|
||||
}
|
||||
}
|
||||
if !generate_new_type {
|
||||
if new_type_miniconf_names.is_empty() {
|
||||
return None;
|
||||
}
|
||||
field.attrs.retain(|attr| {
|
||||
|
Loading…
Reference in New Issue
Block a user