pub struct Config { /* private fields */ }Expand description
Layered configuration document (JSON object internally).
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_yaml(text: &str) -> Result<Config, ConfigError>
pub fn from_yaml(text: &str) -> Result<Config, ConfigError>
Parses a YAML mapping.
§Errors
Returns ConfigError when YAML is invalid or the root is not a mapping.
Sourcepub fn from_toml(text: &str) -> Result<Config, ConfigError>
pub fn from_toml(text: &str) -> Result<Config, ConfigError>
Parses a TOML mapping.
§Errors
Returns ConfigError when TOML is invalid or the root is not a mapping.
§Examples
use serenade_config::Config;
let base = Config::from_toml("[app]\nname = \"shop\"\n").expect("toml");
let overlay = Config::from_toml("[app]\ndebug = true\n").expect("toml");
let merged = base.merged(&overlay);
let params = merged.parameters();
assert_eq!(params.get("app.name").map(String::as_str), Some("shop"));
assert_eq!(params.get("app.debug").map(String::as_str), Some("true"));Sourcepub fn merged(&self, overlay: &Config) -> Config
pub fn merged(&self, overlay: &Config) -> Config
Deep-merges overlay on top of self. Mappings merge; other values replace.
Sourcepub fn interpolate_env(&self) -> Result<Config, ConfigError>
pub fn interpolate_env(&self) -> Result<Config, ConfigError>
Replaces ${VAR} and ${VAR:-default} in string values.
§Errors
Returns ConfigError::MissingEnvironment when a variable has no default and is unset.
Sourcepub fn parameters(&self) -> BTreeMap<String, String>
pub fn parameters(&self) -> BTreeMap<String, String>
Flattened dotted keys for the DI ParameterBag.
Sourcepub fn apply_to(&self, bag: &mut ParameterBag)
pub fn apply_to(&self, bag: &mut ParameterBag)
Copies flattened parameters into bag.
Trait Implementations§
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Forget for Config
impl Freeze for Config
impl Move 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SerializableKey for T
impl<T> SerializableKey for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.