Expand description
Zero-boilerplate configuration management
§Why?
There are a lot of different requirements when selecting, loading and writing a config, depending on the operating system and other environment factors.
In many applications this burden is left to you, the developer of an application, to figure out where to place the configuration files.
This is where confy
comes in.
§Idea
confy
takes care of figuring out operating system
specific and environment paths before reading and
writing a configuration.
It gives you easy access to a configuration file
which is mirrored into a Rust struct
via serde.
This way you only need to worry about the layout of
your configuration, not where and how to store it.
confy
uses the Default
trait in Rust to automatically
create a new configuration, if none is available to read
from yet.
This means that you can simply assume your application
to have a configuration, which will be created with
default values of your choosing, without requiring
any special logic to handle creation.
use serde_derive::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct MyConfig {
version: u8,
api_key: String,
}
/// `MyConfig` implements `Default`
impl ::std::default::Default for MyConfig {
fn default() -> Self { Self { version: 0, api_key: "".into() } }
}
fn main() -> Result<(), confy::ConfyError> {
let cfg = confy::load("my-app-name", None)?;
Ok(())
}
Serde is a required dependency, and can be added with either the serde_derive
crate or serde
crate with feature derive as shown below
[dependencies]
serde = { version = "1.0.152", features = ["derive"] } # <- Only one serde version needed (serde or serde_derive)
serde_derive = "1.0.152" # <- Only one serde version needed (serde or serde_derive)
confy = "^0.5"
Updating the configuration is then done via the store
function.
Enums§
- The errors the confy crate can encounter.
Functions§
- Load an application configuration from disk
- Load an application configuration from a specified path.
- Save changes made to a configuration object
- Save changes made to a configuration object at a specified path
- Save changes made to a configuration object at a specified path
- Save changes made to a configuration object at a specified path