Penguin-config simplifies the creation of config files using serde and serde_json.
toml
[dependencies]
serde = { version = "1.0", features = ["serde_derive"] }
serde_json = { version = "1.0" }
penguin-config = { git = "https://github.com/Henrik-N/penguin-config" }
json
{ "width": 640, "height": 400 }
```rust use penguin_config::*;
// the PenguinConfigGenerate macro will use the std::ops::Default implementation of the struct
struct WindowConfig { width: u32, height: u32, }
fn generateconfig() { WindowConfig::generatepenguinconfigfile(); } ```
```rust use penguin_config::*;
struct WindowConfig { width: u32, height: u32, }
fn readconfig() { let config = WindowConfig::readconfig();
assert_eq!(config.width, 640);
assert_eq!(config.height, 400);
} ```
```rust use penguin_config::*;
struct WindowConfig { width: u32, height: u32, } impl PenguinConfigGenerate for WindowConfig { fn generatepenguinconfigfile() { let config = WindowConfig { width: 640, height: 400 }; Serializer::filepath("window_config.json").serialize(&config); } } ```
```rust use penguin_config::*;
struct WindowConfig { width: u32, height: u32, } impl PenguinConfig for WindowConfig { fn readconfig() -> Self { let config: Self = Deserializer::filepath("window_config.json").deserialize(); config } } ```
Licensed under MIT. Do whatever you want with it :)