#toml-config #file #named

get_config

A simple function to get config from a file

2 releases

0.1.1 Mar 19, 2023
0.1.0 Mar 16, 2023

#74 in #named

29 downloads per month

MIT license

4KB
54 lines

get_config

pub fn main() {
    // There should be either:
    // - a file named `config.toml` in the current directory;
    // - a path passed to `std::env::args().nth(1)`.
    let config: Config = get_config().unwrap();
    println!("{:?}", config);
}
// `Deserialize` is required by `cargo add serde --features derive`
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
struct Config {
    hello: String,
}

Dependencies

~0.5–1.1MB
~25K SLoC