pub struct Config {
pub collection: HashMap<String, Value>,
}Expand description
The object that keeps the data collection.
This is the yaml file to be used in the following tests:
## tests/settings.yaml
user:
name: John
is_real: false
age: 39
height: 1.78
children:
- Huey
- Dewey
- LouieFields§
§collection: HashMap<String, Value>Implementations§
Source§impl Config
impl Config
Sourcepub fn new(source: &str) -> Config
pub fn new(source: &str) -> Config
Creates and return the Config instance given the data source path (can be a file or a folder).
§Examples:
use kalgan_config::Config;
let config: Config = Config::new("tests/settings.yaml");Sourcepub fn get(&self, key: &str) -> Result<Value, String>
pub fn get(&self, key: &str) -> Result<Value, String>
Returns the serde_yaml::Value for the given parameter.
§Examples:
assert_eq!(config.get("user.name").unwrap(), "John");Sourcepub fn get_string(&self, key: &str) -> Result<String, String>
pub fn get_string(&self, key: &str) -> Result<String, String>
Returns the value as a String for the given parameter.
§Examples:
assert_eq!(config.get_string("user.name").unwrap(), "John".to_string());Sourcepub fn get_bool(&self, key: &str) -> Result<bool, String>
pub fn get_bool(&self, key: &str) -> Result<bool, String>
Returns the value as a bool for the given parameter.
§Examples:
assert_eq!(config.get_bool("user.is_real").unwrap(), false);Sourcepub fn get_number(&self, key: &str) -> Result<i64, String>
pub fn get_number(&self, key: &str) -> Result<i64, String>
Returns the value as a i64 for the given parameter.
§Examples:
assert_eq!(config.get_number("user.age").unwrap(), 39);Sourcepub fn get_float(&self, key: &str) -> Result<f64, String>
pub fn get_float(&self, key: &str) -> Result<f64, String>
Returns the value as a f64 for the given parameter.
§Examples:
assert_eq!(config.get_float("user.height").unwrap(), 1.78);Sourcepub fn get_vec(&self, key: &str) -> Result<Vec<Value>, String>
pub fn get_vec(&self, key: &str) -> Result<Vec<Value>, String>
Returns the value as a Vec<serde_yaml::Value> for the given parameter.
§Examples:
assert_eq!(config.get_vec("user.children").unwrap(), vec!["Huey", "Dewey", "Louie"]);pub fn exists(&self, key: &str) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more