Struct Config

Source
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
    - Louie

Fields§

§collection: HashMap<String, Value>

Implementations§

Source§

impl Config

Source

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");
Source

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");
Source

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());
Source

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);
Source

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);
Source

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);
Source

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"]);
Source

pub fn exists(&self, key: &str) -> bool

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.