#configuration #yaml-config #serde #json-toml #config-file


A slim and fast configuration library for Rust

7 releases (3 stable)

3.0.1 Feb 5, 2024
2.0.0 Jun 14, 2023
0.1.3 May 21, 2023

#181 in Configuration

Download history 8/week @ 2024-02-02 44/week @ 2024-02-16 45/week @ 2024-02-23 13/week @ 2024-03-01 20/week @ 2024-03-08 10/week @ 2024-03-15 38/week @ 2024-03-29 8/week @ 2024-04-05

58 downloads per month


378 lines

⚙️ opzioni

A simple and fast configuration library for Rust.


Add the library to your project via cargo:

cargo add opzioni


By default all features are enabled. This allows to work with JSON, TOML and YAML configs.

If you want to only use a subset run:

cargo add opzioni --no-default-features --features json

Replace json with the features you want to enable. The available features are

  • json
  • yaml
  • toml

You can also enable logs via the tracing crate using the tracing feature. This feature is disabled by default


First create a struct implementing Serialize, Deserialize and Default

use serde::{Serialize, Deserialize}

#[derive(Serialize, Deserialize, Default)]
struct MyConfig {
    name: String,
    age: u8

Then just load the config file using opzioni:

let config = opzioni::Config::<MyConfig>::configure().load(std::path::Path::new("myconfig.yml")).unwrap();

opzioni exposes a RwLock which can be used to modify the config data:

let lock = config.get();
let data = lock.read().unwrap();
// or
let mut data = lock.write().unwrap();

Once you are done working with the config you can save the changes to disk by calling save:



~54K SLoC