pub struct Parameters { /* private fields */ }Implementations§
Source§impl Parameters
impl Parameters
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty Parameters instance.
§Examples
use parameterx::Parameters;
let params = Parameters::new();Sourcepub fn insert<K, V>(&mut self, key: K, value: V)
pub fn insert<K, V>(&mut self, key: K, value: V)
Insert a key-value pair into the Parameters.
§Arguments
key- A key that can be converted into aString.value- A value that implements theParameterValuetrait.
§Examples
use parameterx::Parameters;
use parameterx::ParameterValue;
#[derive(Debug, Clone)]
struct MyValue;
impl ToString for MyValue {
fn to_string(&self) -> String {
"my_value".to_string()
}
}
let mut params = Parameters::new();
params.insert("key", MyValue);Sourcepub fn get<T: 'static>(&self, key: &str) -> Option<&T>
pub fn get<T: 'static>(&self, key: &str) -> Option<&T>
Get a reference to a value of type T associated with the given key.
§Arguments
key- A string slice that holds the key.
§Returns
An Option containing a reference to the value if found, or None if not found.
§Examples
use parameterx::Parameters;
use parameterx::ParameterValue;
#[derive(Debug, Clone)]
struct MyValue;
impl ToString for MyValue {
fn to_string(&self) -> String {
"my_value".to_string()
}
}
let mut params = Parameters::new();
params.insert("key", MyValue);
let value: Option<&MyValue> = params.get("key");Sourcepub fn get_required<T: 'static>(&self, key: &str) -> Result<&T>
pub fn get_required<T: 'static>(&self, key: &str) -> Result<&T>
Get a reference to a value of type T associated with the given key, or return an error if not found.
§Arguments
key- A string slice that holds the key.
§Returns
A Result containing a reference to the value if found, or a ParameterError if not found.
§Examples
use parameterx::Parameters;
use parameterx::ParameterValue;
#[derive(Debug, Clone)]
struct MyValue;
impl ToString for MyValue {
fn to_string(&self) -> String {
"my_value".to_string()
}
}
let mut params = Parameters::new();
params.insert("key", MyValue);
let value: Result<&MyValue, _> = params.get_required("key");Sourcepub fn get_string(&self, key: &str) -> Option<String>
pub fn get_string(&self, key: &str) -> Option<String>
Get the string representation of the value associated with the given key.
§Arguments
key- A string slice that holds the key.
§Returns
An Option containing the string representation of the value if found, or None if not found.
§Examples
use parameterx::Parameters;
use parameterx::ParameterValue;
#[derive(Debug, Clone)]
struct MyValue;
impl ToString for MyValue {
fn to_string(&self) -> String {
"my_value".to_string()
}
}
let mut params = Parameters::new();
params.insert("key", MyValue);
let value: Option<String> = params.get_string("key");Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Sourcepub fn try_get<T>(&self, key: &str) -> Result<T>
pub fn try_get<T>(&self, key: &str) -> Result<T>
Try to get a value of type T associated with the given key, converting from a String if necessary.
§Arguments
key- A string slice that holds the key.
§Returns
A Result containing the value if found and successfully converted, or a ParameterError if not found or conversion failed.
§Examples
use parameterx::Parameters;
let mut params = Parameters::new();
params.insert("key", "123".to_string());
let value: Result<String, _> = params.try_get("key");Sourcepub fn with<K, V>(self, key: K, value: V) -> Self
pub fn with<K, V>(self, key: K, value: V) -> Self
Insert a key-value pair into the Parameters and return the modified Parameters.
§Arguments
key- A key that can be converted into aString.value- A value that implements theParameterValuetrait.
§Returns
The modified Parameters.
§Examples
use parameterx::Parameters;
use parameterx::ParameterValue;
#[derive(Debug, Clone)]
struct MyValue;
impl ToString for MyValue {
fn to_string(&self) -> String {
"MyValue".into()
}
}
let params = Parameters::new().with("key", MyValue);