#configuration #file-format #config-file #serde #deserialize #universal

universal-config

A library to simplify reading configuration files from various file formats

10 releases

0.5.0 Mar 30, 2024
0.4.3 Aug 30, 2023
0.4.2 Jul 3, 2023
0.4.1 Jun 5, 2023
0.1.1 Mar 13, 2023

#1263 in Parser implementations

Download history 42/week @ 2023-12-23 23/week @ 2023-12-30 34/week @ 2024-01-06 31/week @ 2024-01-13 67/week @ 2024-01-20 47/week @ 2024-01-27 71/week @ 2024-02-03 65/week @ 2024-02-10 56/week @ 2024-02-17 86/week @ 2024-02-24 75/week @ 2024-03-02 121/week @ 2024-03-09 229/week @ 2024-03-16 157/week @ 2024-03-23 392/week @ 2024-03-30 106/week @ 2024-04-06

900 downloads per month
Used in 3 crates

MIT license

18KB
308 lines

Universal Config

crate | docs | repo

Universal Config is a library for Rust to simplify reading and writing configuration files. It is able to automatically locate config files from standard locations, and has support for various file formats.

The crate does not offer a lot of functionality, leaving that to Serde and your implementation. Instead, it just deals with loading and saving the file.

Currently, the following formats are supported:

  • JSON via serde_json
  • YAML via serde_yaml
  • TOML via toml
  • XML via serde_xml_rs
  • Corn via libcorn
  • Ron via ron

Installation

Just add the crate:

cargo add universal-config

By default, support for all languages is included. You can enable/disable languages using feature flags. For example, in your Cargo.toml:

[dependencies.universal-config]
version = "0.1.0"
default-features = false
features = ["json", "toml"]

Example usage

use universal_config::ConfigLoader;
use serde::Deserialize;

#[derive(Deserialize)]
struct MyConfig {
    foo: String,
}

fn main() {
    let config: MyConfig = ConfigLoader::new("my-app").find_and_load().unwrap();
    println!("{}", config.foo);
}

For more advanced usage, please check the docs.

Dependencies

~2–13MB
~121K SLoC