RSCONFIG-macros

github crates.io docs.rs

Macro implementation for RSCONFIG

Examples

FileConfig

```rust

[derive(Debug, FileConfig)]

struct TestConfig { test: bool } impl YamlConfig for TestConfig { fn fromyaml(yaml: Vec) -> Self { Self { test: *&yaml[0]["test"].asbool().unwrap() } } fn saveyaml(&self, path: &str) -> Result<()> { let mut data = "test: ".tostring(); data.pushstr(self.test.tostring().as_str()); fs::write(path, data).unwrap();

    Ok(())
}

} impl JsonConfig for TestConfig { fn fromjson(val: Value) -> Self { Self { test: val["test"].asbool().unwrap() } } fn savejson(&self, path: &str) -> io::Result<()> { // convert to json pretty format and save let mut m: HashMap<&str, Value> = HashMap::new(); m.insert("test", Value::from(self.test)); let data = serdejson::tostringpretty(&m).unwrap(); fs::write(path, data).unwrap();

    Ok(())
}

} ```