Rust Parameters Library
A flexible and type-safe parameter management system for Rust applications. This library provides multiple ways to store and retrieve typed values using a key-value structure, with support for custom types and various initialization patterns.
Features
- Type-safe parameter storage and retrieval
- Multiple initialization patterns (direct, builder, macro)
- Support for custom types
- Vector type support through
IntVec
- String conversion capabilities
- Zero-cost abstractions with Rust's type system
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0" # Replace with actual version
Usage
Basic Usage
The simplest way to use the Parameters system is through direct insertion and retrieval:
let mut params = new;
params.insert;
params.insert;
params.insert;
// Type-safe retrieval
let name: = params.get;
let age: = params.get;
Builder Pattern
For more complex initialization scenarios, use the builder pattern:
let params = new
.add
.add
.build;
Macro Usage
The library provides a convenient macro for quick parameter creation:
let params = parameters! ;
Custom Types
The system supports custom types that implement the necessary traits:
let person = Person ;
let params = new.with;
API Reference
Parameters
new()
: Creates a new empty Parameters instanceinsert<T>(key: &str, value: T)
: Inserts a value with the given keyget<T>(key: &str) -> Option<&T>
: Retrieves a value by key with type checkingget_string(key: &str) -> Option<String>
: Retrieves a value as a String
ParametersBuilder
new()
: Creates a new builder instanceadd<T>(key: &str, value: T)
: Adds a parameter to the builderbuild()
: Constructs the final Parameters instance
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.