Announcing config_struct - generating structs from config files

Here it is: - v0.2.0

(Technically this is the second release, but the first was extremely rough.)

Basically what this crate allows you to do in a build script, is take a config file (toml/json/yaml/ron):

// config.toml
color = [1.0, 0.0, 0.5]
shape = "square"
scale = 10.0

… and generate a Rust module with a corrsponding struct that allows you to do things like this:

let config = Config::load();
assert_eq!(config.color, [1.0, 0.0, 0.5]);
assert_eq!(config.shape, "square");
assert_eq!(config.scale, 10.0);

You can add and remove properties from the config and the generated struct will change to match.

In debug mode, you can change the config file at runtime and reload it to change properties on the fly. In release mode, the entire config is a const and doesn’t require any actual deserialization at all. (This is also configurable, in case you need dynamic reloading in release mode.)

This was motivated by a desire to make certain properties of my games tweakable at runtime without any complexity or overhead in release mode, and so far I’ve already found it useful. I hope others will too - and if you find it’s missing a feature that you’d like, let me know. :slight_smile:


I will have to try, I was looking for something like this, thanks!

1 Like