diff options
Diffstat (limited to 'readme.md')
-rw-r--r-- | readme.md | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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"] | ||
11 | struct AppConfig { | 12 | struct AppConfig { |
12 | version: u8, | 13 | -- snip -- |
13 | path: String, | ||
14 | } | 14 | } |
15 | 15 | ||
16 | // `Configure` exposes `load` and `store` | ||
16 | fn main() { | 17 | fn 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 | |||
25 | You can specify a path to be used, unless you want to stick | ||
26 | with 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 | ``` | ||