Crate config_file2
source ·Expand description
§config-file
Extreamly easy to load and store your configuration file!
§Features
toml(enabled by default)jsonxmlyaml
§Examples
use config_file2::{LoadConfigFile, StoreConfigFile};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Config {
host: String,
}
// store
Config { host: "example.com".into() }.store("/tmp/myconfig.toml").unwrap();
// load
let config = Config::load("/tmp/myconfig.toml").unwrap();
assert_eq!(config.host.as_str(), "example.com");§more functions
ⓘ
fn load_with_specific_format(path: impl AsRef<Path>, config_type: ConfigFormat) -> Result<Self>;
fn load_or_default(path: impl AsRef<Path>) -> Result<Self>;
fn store_with_specific_format(self, path: impl AsRef<Path>, config_type: ConfigFormat) -> Result<()>;
fn store_without_overwrite(self, path: impl AsRef<Path>) -> Result<()>;Re-exports§
pub use error::Result;
Modules§
Enums§
- Format of configuration file.
Traits§
- Trait for loading a struct from a configuration file. This trait is automatically implemented when
serde::Deserializeis. - Trait for storing a struct into a configuration file. This trait is automatically implemented when
serde::Serializeis.