cfgfifo

Crates.iocfgfifo
lib.rscfgfifo
version
sourcesrc
created_at2023-10-30 14:43:57.542136
updated_at2025-02-10 21:05:52.70807
description(De)serialize common configuration file formats based on file extension
homepage
repositoryhttps://github.com/jwodder/cfgfifo
max_upload_size
id1018549
Cargo.toml error:TOML parse error at line 20, column 1 | 20 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
John T. Wodder II (jwodder)

documentation

README

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io Minimum Supported Rust Version MIT License

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(())
}
Commit count: 90

cargo fmt