From bf2d5479e353895496b735700ec2ec08713cccc3 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 19 Mar 2020 17:20:59 +0530 Subject: add new sample usage --- readme.md | 30 ++++++++++++++++++++++++------ 1 file 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 @@ ### example ```rust -#[derive(Config, Default, Serialize, Deserialize)] -#[filename = "config"] // ~/.config/appconfig/config.toml (XDG spec) -#[extension = "toml"] // possible values: yaml, toml, json +// derive the `Configure` trait, and specify the +// `config_file` attribute +#[derive(Configure, Default, Serialize, Deserialize)] +#[config_file = "config.toml"] struct AppConfig { - version: u8, - path: String, + -- snip -- } +// `Configure` exposes `load` and `store` fn main() { let mut config = AppConfig::load().unwrap(); - config.version = 3; + config.version = 2; config.path = "/home/np".to_string(); config.store(); } ``` + +You can specify a path to be used, unless you want to stick +with the defaults: + +```rust +// load from and store in user's home directory +#[config_file = "~/config.toml"] +``` + +`fondant` supports `yaml`, `toml` and `json`, defaults to +`toml`: + +```rust +#[config_file = "config.toml"] +#[config_file = "my_app_config.yaml"] +#[config_file = "~/.app.conf.json"] +``` -- cgit v1.2.3