Crates.io | tide_rs |
lib.rs | tide_rs |
version | 0.1.0 |
source | src |
created_at | 2023-12-25 15:55:48.554472 |
updated_at | 2023-12-25 15:55:48.554472 |
description | A rust library of the TIDE configuration parser |
homepage | |
repository | https://github.com/tideconf/tide_rs |
max_upload_size | |
id | 1080329 |
size | 23,732 |
tide_rs is a flexible config parser for Rust, designed to handle the TIDE configuration format. It provides an easy-to-use API for accessing configuration values from TIDE files.
See TIDE for more information on the TIDE configuration format.
[!IMPORTANT]
This is no more than a hobby project at the moment. I have always been curious about the design and implementation of configuration frameworks, and this is my attempt at creating one. I am not sure if this will ever be used, but I am hoping to learn a bit more about the whole deal of configuration handling. If you are interested in this project, please feel free to contribute or provide feedback.
Add the following to your Cargo.toml
file:
[dependencies]
tide_rs = "0.1.0"
use tide_rs::TIDE;
use tide_rs::ConfigValue;
fn main() {
let config_file_path = "./path/tp/config.tide";
let tide_config = match TIDE::new(config_file_path) {
Ok(cfg) => cfg,
Err(e) => {
eprintln!("Failed to load configuration: {:?}", e);
return;
}
};
// Use get_config_value method to access configuration values
// Example of accessing a string value.
match tide_config.get_config_value("database.type") {
Ok(ConfigValue::String(value)) => println!("Database type: {}", value),
_ => println!("Database type not found or not a string."),
}
}
TIDE configuration values can be overridden by environment variables. The environment variable name is the uppercased path to the configuration value, with the path separator replaced by an underscore.
For example database.credentials.username
would be overridden by the
DATABASE_CREDENTIALS_USERNAME
environment variable.
An example of using tide_rs to parse a TIDE file, is available in the examples directory.
cargo run --example main
Contributions are welcome. Please feel free to open an issue or submit a pull request.