Struct lazy_conf::get::GetHolder

source ·
pub struct GetHolder {
    pub v: Vec<(GetMode, Box<dyn Getable>)>,
    pub help_mess: String,
    pub fails: String,
}
Expand description

The GetHolder does the work of maintaining a list of Getables, and prioritizing user requests.

Normally you will not instantiate this directly, prefering to use the config() method to create it.

However it can be instatiated to use anything that implements Getable (from this module)

For example

use lazy_conf::{Getable,GetHolder,GetMode};
use std::collections::BTreeMap;
 
struct GetTester(BTreeMap<String,String>);

impl Getable for GetTester{
  fn get(&self,s:&str)->Option<String>{
      self.0.get(s).map(|s|s.to_string())
   }
}

let mut g = GetHolder::new();
let mut t1 = BTreeMap::new();
t1.insert("a".to_string(),"a_t1_res".to_string());
let mut t2 = BTreeMap::new();
t2.insert("a".to_string(),"a_t2_res".to_string());
t2.insert("num".to_string(),"4".to_string());
g.add(GetMode::Conf,GetTester(t1));
g.add(GetMode::Flag,GetTester(t2));

assert_eq!(&g.grab().cf("a").fg("a").s().unwrap(),"a_t1_res");
assert_eq!(&g.grab().fg("a").cf("a").s().unwrap(),"a_t2_res");
assert_eq!(g.grab().cf("num").fg("num").t::<i32>().unwrap(),4);
assert!(g.grab().s().is_none());
assert!(g.grab().fg("b").cf("b").s().is_none());

Fields§

§v: Vec<(GetMode, Box<dyn Getable>)>§help_mess: String§fails: String

Implementations§

Checks for a –help flag, and prints the built up help message to stdout, returns true if

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.