[−][src]Struct blather::Params
Key/value parameters storage.
Implementations
impl Params
[src]
pub fn new() -> Self
[src]
Create a new empty parameters object.
pub fn clear(&mut self)
[src]
Reset all the key/values.
pub fn get_inner(&self) -> &HashMap<String, String>
[src]
pub fn add_param<T: ToString, U: ToString>(&mut self, key: T, value: U)
[src]
Add a parameter to the parameter.
pub fn add_str<T: ToString, U: ToString>(&mut self, key: T, value: U)
[src]
Add a string parameter to the parameter.
pub fn have(&self, key: &str) -> bool
[src]
Returns true if the parameter with key
exists. Returns false
otherwise.
pub fn get_param<T: FromStr>(&self, key: &str) -> Result<T, Error>
[src]
Get a parameter and convert it to a requested type.
pub fn get_str(&self, key: &str) -> Option<&str>
[src]
Get string representation of a value for a requested key.
Returns None
if the key is not found in the inner storage. Returns
Some(&str)
otherwise.
pub fn get_int<T: FromStr>(&self, key: &str) -> Result<T, Error>
[src]
Get a parameter and convert it to an integer type. The logic of this
method is identical to get_param()
.
use blather::Params; fn main() { let mut params = Params::new(); params.add_param("Num", 7); assert_eq!(params.get_int::<usize>("Num").unwrap(), 7); }
This method should really have some integer trait bound, but it doesn't seem to exist in the standard library.
This method exists primarily to achive some sort of parity with a corresponding C++ library.
pub fn get_int_def<T: FromStr>(&self, key: &str, def: T) -> Result<T, Error>
[src]
Try to get the value of a key and interpret it as an integer. If the key does not exist then return a default value supplied by the caller.
use blather::Params; fn main() { let mut params = Params::new(); params.add_param("num", 11); assert_eq!(params.get_int_def::<u32>("num", 5).unwrap(), 11); assert_eq!(params.get_int_def::<u32>("nonexistent", 17).unwrap(), 17); }
pub fn calc_buf_size(&self) -> usize
[src]
Calculate the size of the buffer in serialized form. Each entry will be a newline terminated utf-8 line. Last line will be a single newline character.
pub fn serialize(&self) -> Result<Vec<u8>, Error>
[src]
pub fn into_inner(self) -> HashMap<String, String>
[src]
Consume the Params buffer and return the internal parameters HashMap.
Trait Implementations
impl Clone for Params
[src]
impl Debug for Params
[src]
impl Default for Params
[src]
impl Display for Params
[src]
impl From<HashMap<String, String, RandomState>> for Params
[src]
impl From<Params> for Telegram
[src]
Auto Trait Implementations
impl RefUnwindSafe for Params
impl Send for Params
impl Sync for Params
impl Unpin for Params
impl UnwindSafe for Params
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,