Crates.io | glider_config |
lib.rs | glider_config |
version | 0.1.2 |
source | src |
created_at | 2024-10-29 19:36:51.936634 |
updated_at | 2024-11-21 01:16:21.007 |
description | A minimal configuration loader for JSON, TOML, and YAML formats. |
homepage | |
repository | |
max_upload_size | |
id | 1427546 |
size | 5,515 |
glider_config
is a minimal Rust library for loading configuration files in JSON, TOML, and YAML formats. This crate is designed to keep things lightweight and simple, making it easy to integrate basic configuration management into your Rust projects.
Add glider_config
to your Cargo.toml
:
[dependencies]
glider_config = "0.1.0"
Supports JSON, TOML, and YAML configuration formats. Loads configurations into a single, easy-to-use serde_json::Value format. Minimal dependencies for quick and easy integration.
Here's a basic example of how to use glider_config to load a configuration file:
use glider_config::{load_config, ConfigFormat};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a JSON config file
let config = load_config("path/to/config.json", ConfigFormat::Json)?;
// Access configuration values
if let Some(volume) = config.get("volume") {
println!("Volume setting: {}", volume);
}
Ok(())
}
Supported Formats
JSON: Use ConfigFormat::Json to load JSON configuration files.
TOML: Use ConfigFormat::Toml to load TOML files.
YAML: Use ConfigFormat::Yaml for YAML configuration files.
Below is an example showing how to load and print values from each configuration type:
use glider_config::{load_config, ConfigFormat};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a TOML configuration file
let config = load_config("path/to/config.toml", ConfigFormat::Toml)?;
println!("Loaded configuration: {:?}", config);
// Access a specific value
if let Some(value) = config.get("key") {
println!("Value for 'key': {:?}", value);
}
Ok(())
}
Run the test suite with: cargo test
This project is licensed under the MIT License.
bensatlantik