10 releases (breaking)
Uses new Rust 2024
| 0.8.0 | Feb 16, 2026 |
|---|---|
| 0.7.0 | Dec 8, 2025 |
| 0.6.0 | Nov 14, 2025 |
| 0.4.0 | Jul 14, 2025 |
| 0.1.0 | Oct 30, 2023 |
#984 in Encoding
60 downloads per month
Used in labelmaker
65KB
914 lines
GitHub | crates.io | Documentation | Issues | Changelog
cfgfifo is a Rust library for serializing & deserializing various common
configuration file formats (JSON, JSON5, RON, TOML, and
YAML), including autodetecting the format of a file based on its file
extension. It's good for application authors who want to support multiple
configuration file formats but don't want to write out a bunch of boilerplate.
cfgfifo has already written that boilerplate for you, so let it (de)serialize
your files!
Example
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
struct AppConfig {
#[serde(default)]
enable_foo: bool,
#[serde(default)]
bar_type: BarType,
#[serde(default)]
flavor: Option<String>,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
enum BarType {
#[default]
Open,
Closed,
Clopen,
}
fn main() -> anyhow::Result<()> {
let Some(cfgpath) = std::env::args().nth(1) else {
anyhow::bail!("No configuration file specified");
};
// cfgfifo identifies the format used by the file `cfgpath` based on its
// file extension and deserializes it appropriately:
let cfg: AppConfig = cfgfifo::load(cfgpath)?;
println!("You specified the following configuration:");
println!("{cfg:#?}");
Ok(())
}
Dependencies
~1.4–2.5MB
~60K SLoC