#ron #file #write

ronfig

Config rust with RON, Easily!

2 releases

0.1.1 Apr 9, 2021
0.1.0 Feb 3, 2021

#951 in Configuration

MIT license

10KB
199 lines

RONFIG

Config rust with RON, Easily!

For now, it's just a copy of amethyst_config.

Usage

Add this to Cargo.toml

[dependencies]
ronfig = "0.1"

Example RON file

(
    app_name:"simple app",
    workers: 4,
    debug: Some(true),
)
use std::path::Path;
use serde::{Deserialize, Serialize};
use ronfig::Config;

/// Your struct should at least derive `serde`'s `Serialize` and `Deserialize` to
/// be able to read and write the ron file.
#[derive(Debug, Deserialize, Serialize)]
struct SimpleConfig {
    app_name: String,
    workers: usize,
    debug: Option<bool>,
}

fn main() {
    let path = Path::new("./resources/examples/simple-config.ron");
    let result = SimpleConfig::load(path);
    match result {
        Ok(simple_config) => {
            println!("Config loaded from file:\n\t {:?}", &path);
            println!("{:?}", &simple_config);
        }
        Err(config_error) => {
            println!("Error loading the config:\n\t{:?}", &config_error);
        }
    };
}

Dependencies

~5MB
~155K SLoC