Crates.io | confee |
lib.rs | confee |
version | 0.1.3 |
source | src |
created_at | 2024-10-14 18:02:26.868953 |
updated_at | 2024-10-14 19:52:50.550258 |
description | Parse your simple configuration files with confee for a good time :) |
homepage | |
repository | https://github.com/r0bin-dood/confee |
max_upload_size | |
id | 1408525 |
size | 9,715 |
Parse your simple configuration files in an ergonomic and safe way! :)
Available in crates.io
To use confee, your configurations should follow this format:
[key][delim][value]\n
key
: Any sequence of printable characters.delim
: A delimiter character, such as ':'
, ' '
, '='
, etc.value
: Any sequence of printable characters.Each new line represents a new key-value pair.
https://github.com/r0bin-dood/confee/blob/main/examples/example.conf
log: stdout
dir: ./example/
addr: 127.0.0.1
port: 8080
https://github.com/r0bin-dood/confee/blob/main/examples/main.rs
use std::env;
use confee::conf::*;
use std::net::IpAddr;
use std::path::{Path, PathBuf};
macro_rules! conf_defaults {
() => {
[
("log".to_string(), "stdout".to_string()),
("dir".to_string(), "/var/www/html/".to_string()),
("addr".to_string(), "127.0.0.1".to_string()),
("port".to_string(), "8080".to_string()),
]
};
}
fn main() {
let args: Vec<String> = env::args().collect();
let mut conf = Conf::from(conf_defaults!());
match conf.with_file(&args[1]).update() {
Ok(_) => println!("Successfully updated configuration!"),
Err(e) => panic!("Error updating configuration: {}", e),
}
let dir: PathBuf = conf.get("dir").unwrap();
let addr: IpAddr = conf.get("addr").unwrap();
let port: u16 = conf.get("port").unwrap();
println!("log: {}", conf["log"]);
println!("dir: {}", dir.to_string_lossy());
println!("addr: {}", addr);
println!("port: {}", port);
dbg!(conf);
}
Run cargo doc --open
to view in-code docummentation locally, or visit: