#config-file #yaml #toml #manage #yaml-parser #deserialize #xcfg

bin+lib xcfg-rs

A simple configuration file parser for Rust

6 releases

new 0.2.4 Apr 20, 2024
0.2.3 Apr 19, 2024
0.2.2 Mar 5, 2024
0.1.0 Feb 27, 2024

#1374 in Encoding

36 downloads per month

MIT license

15KB
392 lines

config-rs

a simple tool to manage config file

plan

  • intergrate with toml, yaml.....
  • update regualarly ...

lib.rs:

xcfg_rs is a simple configuration file loader and saver.

Example

use serde::{Deserialize, Serialize};
use xcfg::File;
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct Test {
    a: i32,
    b: Vec<i32>,
    sub: SubTest,
}
impl Default for Test {
    fn default() -> Self {
        Self {
            a: 0,
            b: vec![],
            sub: SubTest::default(),
        }
    }
}

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct SubTest {
    c: Vec<String>,
}
impl Default for SubTest {
    fn default() -> Self {
        Self { c: vec![] }
    }
}

let test = Test {
    a: 1,
    b: vec![0, 1, 2],
    sub: SubTest {
        c: vec!["ab".to_string(), "cd".to_string()],
    },
};
let path = "./test.toml";
let mut f = File::default().path(path);
f.inner = test.clone();
f.save().unwrap();
f.inner = Test::default();
f.load().unwrap();
assert_eq!(f.inner, test);
std::fs::remove_file(path).unwrap();

Dependencies

~0.3–0.9MB
~18K SLoC