config-file2
Extremely easy to load and store your configuration file!
Usage
- Add dependency:
- Enable which format you want to use in features.
When atomic is enabled, stores write to a temporary file in the target's directory and rename it into place.
Here's an example of how to use it with json and yaml format:
[]
= { = "0.4", = ["json", "yaml"] }
Examples
use ;
use ;
// store
Config .store.unwrap;
// load
let config = load.unwrap.unwrap;
assert_eq!;
Another way to store a struct into a configuration file, where the struct owns
its path via [Storable]:
use Storable;
use Serialize;
use ;
TestStorable .save.unwrap;
Storing with options (builder)
When you need control over pretty-printing, overwriting, or the format, use a
builder. For an explicit path use [StoreConfigFile::store_opts]:
use StoreConfigFile;
use Serialize;
;
// pretty off, no overwrite, format still auto-detected from the extension.
Config
.store_opts
.pretty
.overwrite
.execute
.unwrap;
For a type implementing [Storable], use [Storable::save_opts] (bound to the
intrinsic path):
use Storable;
config.save_opts.pretty.execute.unwrap;
more
;
;
;
;
;
// Storable:
;
;