-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.rs
29 lines (23 loc) · 808 Bytes
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use fast_config::Config;
use serde::{Serialize, Deserialize};
// Creating a config struct to store our data
#[derive(Serialize, Deserialize)]
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();
}