Config Helper
Config Helper is a simple and flexible library for handling configuration files in various formats, such as TOML, JSON, and YAML. It allows you to easily load and save configuration data to and from these formats and automatically deserializes them into Rust structs.
Features
- Multi-format support: Handles TOML, JSON, and YAML configuration files.
- Easy deserialization: Convert configuration files into Rust structs.
- Serialization support: Convert Rust structs back into configuration files in the specified format.
- Flexible API: Simple functions for loading and saving configuration data.
Installation
To use Config Helper in your project, add it as a dependency in your Cargo.toml:
[]
= "0.1.1"
Usage
Define a Configuration Struct
First, define a struct that matches the configuration format you expect to load.
use ;
Loading Configuration from a File
Use the load_config function to load a configuration file. It automatically detects the file format (TOML, JSON, or YAML) based on the file extension.
use ;
Saving Configuration to a File
Use the save_config function to save a Rust struct as a configuration file. The file format is determined by the file extension.
use ;
Supported Formats
- TOML: Common format for Rust configuration files.
- JSON: Widely used and human-readable format.
- YAML: Often used for more complex configuration data.
Error Handling
The library returns a Result type for both loading and saving configurations. Errors may occur due to invalid file format, deserialization issues, or I/O errors. Make sure to handle these errors appropriately in your application.
Contributing
Feel free to open issues or submit pull requests for any improvements or bug fixes. Contributions are always welcome!
- Fork the repository.
- Create a branch for your feature or bug fix.
- Make your changes and test thoroughly.
- Submit a pull request with a clear explanation of your changes.
License
This project is licensed under the MPL-2.0 License - see the LICENSE file for details.