Config

Trait Config 

Source
pub trait Config {
    // Required method
    fn get(&self, key: &str) -> Option<String>;

    // Provided methods
    fn must_get(&self, key: &str) -> String { ... }
    fn string(&self, key: &str) -> String { ... }
    fn int(&self, key: &str) -> i64 { ... }
    fn float(&self, key: &str) -> f64 { ... }
    fn bool(&self, key: &str) -> bool { ... }
    fn duration(&self, key: &str) -> Duration { ... }
    fn datetime(&self, key: &str) -> DateTime<Utc> { ... }
    fn list(&self, key: &str) -> Vec<String> { ... }
    fn map(&self, key: &str) -> HashMap<String, String> { ... }
}
Expand description

The main trait for this package. This should be implemented if you want to use this package with your configuration systems.

Required Methods§

Source

fn get(&self, key: &str) -> Option<String>

Returns the value associated with the given key.

Provided Methods§

Source

fn must_get(&self, key: &str) -> String

Similar to get but panics if there is no value.

Source

fn string(&self, key: &str) -> String

Get the value as a string or panics if one isn’t found.

Source

fn int(&self, key: &str) -> i64

Get the value as an integer or panics if one isn’t found or cannot be parsed.

Source

fn float(&self, key: &str) -> f64

Get the value as a float or panics if one isn’t found or cannot be parsed.

Source

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

Get the value as a bool or panics if one isn’t found or cannot be parsed. The following case-insensitive values are considered true: t, true, 1, y, yes. All other values are considered false.

Source

fn duration(&self, key: &str) -> Duration

Get the value as a duration or panics if one isn’t found or can’t be parsed. Thre doesn’t appear to be a parsing function for a duration, so it attempts to convert to an integer and use that as the number of seconds.

Source

fn datetime(&self, key: &str) -> DateTime<Utc>

Get the value as a duration or panics if one isn’t found or it can’t be parsed. It uses RFC339 to parse it.

Source

fn list(&self, key: &str) -> Vec<String>

Get a list or panics if one isn’t found. The list should be a comma-delimited list surrouned by brackets (e.g. [1, 2, 3] => vec![“1”, “2”, “3”].

Source

fn map(&self, key: &str) -> HashMap<String, String>

Get a map or panics if one isn’t found. The list should be a comma-delimited list surrouned by braces with key/value pairs associated with => (e.g. {a=>1, b=>2, c=>3} => ((a,1), (b,2), (c,3))).

Implementations on Foreign Types§

Source§

impl Config for HashMap<&str, &str>

Source§

fn get(&self, key: &str) -> Option<String>

Implementors§