ronfig

Crates.ioronfig
lib.rsronfig
version0.1.1
sourcesrc
created_at2021-02-03 19:59:40.895333
updated_at2021-04-09 19:25:10.248834
descriptionConfig rust with RON, Easily!
homepage
repositoryhttps://github.com/mojtab23/ronfig
max_upload_size
id350205
size15,795
Mojtaba (mojtab23)

documentation

README

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);
        }
    };
}
Commit count: 11

cargo fmt