aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-03-19 11:50:59 +0000
committerAkshay <[email protected]>2020-03-19 11:50:59 +0000
commitbf2d5479e353895496b735700ec2ec08713cccc3 (patch)
treef5e61e372a5a1924346e6de91ecbd29ea2859d2d
parentca0dc4be5174481b0fe3ce0483df00fe44b55b51 (diff)
add new sample usage
-rw-r--r--readme.md30
1 files changed, 24 insertions, 6 deletions
diff --git a/readme.md b/readme.md
index d3f4ad8..1e6de1e 100644
--- a/readme.md
+++ b/readme.md
@@ -5,18 +5,36 @@
5### example 5### example
6 6
7```rust 7```rust
8#[derive(Config, Default, Serialize, Deserialize)] 8// derive the `Configure` trait, and specify the
9#[filename = "config"] // ~/.config/appconfig/config.toml (XDG spec) 9// `config_file` attribute
10#[extension = "toml"] // possible values: yaml, toml, json 10#[derive(Configure, Default, Serialize, Deserialize)]
11#[config_file = "config.toml"]
11struct AppConfig { 12struct AppConfig {
12 version: u8, 13 -- snip --
13 path: String,
14} 14}
15 15
16// `Configure` exposes `load` and `store`
16fn main() { 17fn main() {
17 let mut config = AppConfig::load().unwrap(); 18 let mut config = AppConfig::load().unwrap();
18 config.version = 3; 19 config.version = 2;
19 config.path = "/home/np".to_string(); 20 config.path = "/home/np".to_string();
20 config.store(); 21 config.store();
21} 22}
22``` 23```
24
25You can specify a path to be used, unless you want to stick
26with the defaults:
27
28```rust
29// load from and store in user's home directory
30#[config_file = "~/config.toml"]
31```
32
33`fondant` supports `yaml`, `toml` and `json`, defaults to
34`toml`:
35
36```rust
37#[config_file = "config.toml"]
38#[config_file = "my_app_config.yaml"]
39#[config_file = "~/.app.conf.json"]
40```