pub struct Config { /* private fields */ }Expand description
Merged configuration for one environment.
Implementations§
Source§impl Config
impl Config
Sourcepub fn current() -> Result<Config>
pub fn current() -> Result<Config>
The app’s config, as App::config was given it: for code that
builds what the app builds from it outside a request, as a webhook
handler building a client does (Stripe.new()?).
§Errors
Before the app is configured.
Sourcepub fn make_current(&self)
pub fn make_current(&self)
Makes this the config Config::current gives. App::config calls it.
pub fn load_from(dir: impl AsRef<Path>, env: Env) -> Result<Self>
Sourcepub fn load_embedded(files: &[(&str, &str)]) -> Result<Self>
pub fn load_embedded(files: &[(&str, &str)]) -> Result<Self>
Like Config::load, from files compiled into the binary:
(name, contents) pairs such as ("production", "…"), as
glacier::config!() passes them in release builds. Environment
variables still override them.
Sourcepub fn load_embedded_as(files: &[(&str, &str)], env: Env) -> Result<Self>
pub fn load_embedded_as(files: &[(&str, &str)], env: Env) -> Result<Self>
Config::load_embedded for a given environment.
Sourcepub fn from_toml(env: Env, source: &str) -> Result<Self>
pub fn from_toml(env: Env, source: &str) -> Result<Self>
Builds a config from a TOML string, without touching the filesystem or environment. Handy in tests.
pub fn env(&self) -> Env
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T>
Reads a dotted key such as "database.pool_size".
Sourcepub fn get_opt<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub fn get_opt<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
Like get, but a missing key is Ok(None).
Sourcepub fn secret(&self, key: &str, env_var: &str) -> Result<Option<String>>
pub fn secret(&self, key: &str, env_var: &str) -> Result<Option<String>>
A secret, such as an API key: the config’s key (which an
environment variable overrides as usual: stripe.api_key from
GLACIER__STRIPE__API_KEY), or else the service’s own variable,
env_var (STRIPE_API_KEY), as other tools set it. None when
neither is set; an empty value counts as unset.
Tests read only the config (and GLACIER__… variables): a real key
left in a developer’s shell never reaches them.
let key = config.secret("stripe.api_key", "STRIPE_API_KEY")?;Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T>
Deserializes the whole config into an app-defined struct.
Sourcepub fn url(&self) -> Result<String>
pub fn url(&self) -> Result<String>
The app’s public address, https://example.com, for absolute links
such as a reset link in a mail: url from the config, or outside
production the address the server listens on. Never the request’s
Host header, which whoever sends the request chooses.
§Errors
In production without a url.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more