| Crates.io | parameterx |
| lib.rs | parameterx |
| version | 0.1.0 |
| created_at | 2025-02-13 16:43:15.715489+00 |
| updated_at | 2025-02-13 16:43:15.715489+00 |
| description | 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. |
| homepage | |
| repository | https://github.com/kulapoo/parameterx |
| max_upload_size | |
| id | 1554467 |
| size | 23,755 |
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.
IntVecAdd this to your Cargo.toml:
[dependencies]
parameters = "0.1.0" # Replace with actual version
The simplest way to use the Parameters system is through direct insertion and retrieval:
let mut params = Parameters::new();
params.insert("name", "Alice");
params.insert("age", 30);
params.insert("height", 5.9f64);
// Type-safe retrieval
let name: Option<&str> = params.get("name");
let age: Option<i32> = params.get("age");
For more complex initialization scenarios, use the builder pattern:
let params = ParametersBuilder::new()
.add("name", "Bob")
.add("scores", IntVec::<i32>(vec![85, 92, 78]))
.build();
The library provides a convenient macro for quick parameter creation:
let params = parameters! {
"name" => "Charlie",
"age" => "25",
};
The system supports custom types that implement the necessary traits:
#[derive(Debug, Clone)]
struct Person {
name: String,
age: i32,
}
impl ToString for Person {
fn to_string(&self) -> String {
format!("{} ({})", self.name, self.age)
}
}
let person = Person {
name: "Dave".to_string(),
age: 35,
};
let params = Parameters::new().with("person", person);
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 Stringnew(): Creates a new builder instanceadd<T>(key: &str, value: T): Adds a parameter to the builderbuild(): Constructs the final Parameters instanceContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.