fondant
fondant
is a macro based library to take the boilerplate out of
configuration handling. Most of fondant
is based off the confy
crate.
fondant
adds a couple of extra features:
- support for json, yaml and toml
- support for custom config paths
- support for custom config file names
Sample usage
// the struct has to derive Serialize, Deserialize and Default
// |
// `-- this attribute sets the file name to "config.toml"
// `-- the file format to "toml"
// `-- the file path to "default" (read the notes below)
Notes:
load
returnsDefault::default
if the config file is not present, and stores a serializedDefault::default
at the specified path- the "default" config path varies by platform:
- GNU/Linux:
$XDG_CONFIG_HOME/my_cool_crate/config.toml
(follows xdg spec) - MacOS:
$HOME/Library/Preferences/my_cool_crate/config.toml
- Windows:
{FOLDERID_RoamingAppData}\_project_path_\config
- GNU/Linux:
Customization
Set your own filename, for ex.: apprc
// effective path: $XDG_CONFIG_HOME/my_cool_crate/apprc.toml
// effective format: toml
Change file format to yaml
, by changing the file extension.
Supported extensions are yaml
, toml
, json
:
// effective path: $XDG_CONFIG_HOME/my_cool_crate/config.yaml
// effective format: yaml
Override the default config path, for ex.: the home directory (it is not recommended to override config path):
// effective path: $HOME/.apprc.json
// effective format: json
Fondant meshes well with Serde, for ex.:
Above snippet produces this config file:
= 'Central Park Zoo'
= 4
todo
- improve error from trait impl
- use
syn::Error
andsyn::Result
to report macro errors - write docs
- bundle and publish to crates.io