fast_config
A small, safe, lightweight, and easy-to-use Rust crate to read and write to config files.
Currently only supports: JSON5, TOML, and YAML.
But more Serde-supported formats (such as RON) are planned to be added later.
fast_config
was made to be a faster to set up, more light-weight, statically typed alternative to config.
It also manages to have its own benefits compared to some other config-reading crates as there is full support for writing/saving config files, and it also provides you with some options regarding styling your config files
key0
to key9000
in an object)2 and 3 are going to be addressed with future updates, however.
This crate is now stable, I however haven't battle-tested this in any humongous projects, so while there will NOT be any panics or crashes, some weird things might happen at scale.
Documentation might be a little weird or incomplete at the current moment, too.
Feel free to contribute any fixes by opening up an issue if you find anything that isn't working as expected!
```rust,ignore use fast_config::Config; use serde::{Serialize, Deserialize};
// Creating a config struct to store our data
pub struct MyData { pub student_debt: i32 }
fn main() { // Initializing a logging system (needed to show some warnings/errors) env_logger::init();
// Creating our data (default values)
let data = MyData {
student_debt: 20
};
// Creating a new config struct with our data struct
let mut config = Config::new("./config/myconfig.json5", data).unwrap();
// Read/writing to the data
println!("I am ${} in debt", config.data.student_debt);
config.data.student_debt = i32::MAX;
println!("Oh no, i am now ${} in debt!!", config.data.student_debt);
// Saving it back to the disk
config.save().unwrap();
} ```
Add the crate to your project via
cargo add fast_config
serde
as it is required!Enable the feature(s) for the format(s) you'd like to use
json5
, toml
, and yaml
are supported Serialize
and Deserialize
Optionally use
the crate's Config
type for convenience
use fast_config::Config;
Use
rust,ignore
let my_config = Config::new("./path/to/my_config_file", your_data).unwrap();
to create and store your config file(s)!
Alternatively you could also use Config::from_settings
to style some things and manually set the format!
View the examples directory for more advanced examples.