aboutsummaryrefslogtreecommitdiff
path: root/readme.md
blob: 9378ccc8d6d8aee3ebd52a4ade003c3c5a48a3f9 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# fondant

[Documentation](https://docs.rs/fondant/) ·
[Architecture](#Architecture) · [Usage](#Usage) ·
[Customization](#Customization) · [Todo](#Todo)

`fondant` is a macro based library to take the boilerplate out of
configuration handling. All you need to do is derive the
`Configure` trait on your struct, and `fondant` will decide
where to store it and and how to do so safely.


Most of `fondant` is based off the `confy` crate,
with a couple of extra features:

 - support for json, yaml and toml
 - support for custom config paths
 - support for custom config file names

### Usage ([Full Documentation](https://docs.rs/fondant/))

Drop this in your `Cargo.toml` to get started:

```
[dependencies]
fondant = "0.1.0"
```

Derive the macro:

```rust
// the struct has to derive Serialize, Deserialize and Default
use fondant::Configure;
use serde::{Serialize, Deserialize};

#[derive(Configure, Serialize, Deserialize, Default)]
#[config_file = "config.toml"]
struct AppConfig {
    port: u32,
    username: String,
}

fn main() {
    // use `load` to load the config file
    // loads in Default::default if it can't find one
    let mut conf = AppConfig::load().unwrap();

    // do stuff with conf
    conf.port = 7878;

    // call `store` to save changes
    conf.store().unwrap();
}
```

Find more examples and options at [docs.rs](https://docs.rs/fondant/).

### Architecture

`fondant` is split into 3 separate crates:

 - `fondant_deps`: external crates and utils that `fondant` requires
 - `fondant_derive`: core macro definitions
 - `fondant`: the user facing library that brings it all together

This slightly strange architecture arose because of some
limitations with proc-macro crates and strict cyclic
dependencies in cargo. All you need is the `fondant` crate.


### Todo

 - [ ] improve error types
 - [ ] use `syn::Error` and `syn::Result` to report macro errors
 - [x] write docs
 - [x] bundle and publish to crates.io