glider_config

Crates.ioglider_config
lib.rsglider_config
version0.1.2
sourcesrc
created_at2024-10-29 19:36:51.936634
updated_at2024-11-21 01:16:21.007
descriptionA minimal configuration loader for JSON, TOML, and YAML formats.
homepage
repository
max_upload_size
id1427546
size5,515
Ben Santora (bensatlantik)

documentation

README

glider_config

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.

Installation

Add glider_config to your Cargo.toml:

[dependencies]
glider_config = "0.1.0"

Features

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.

Usage

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.

Example Code

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(())
}

Running Tests

Run the test suite with: cargo test

License

This project is licensed under the MIT License.

Author

bensatlantik

Commit count: 0

cargo fmt