Struct kalgan_config::Config
source · [−]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
- Louie
Fields
collection: HashMap<String, Value>
Implementations
sourceimpl 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 RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more