pub struct Config<T>(pub T)
where
T: Clone;Expand description
A typed configuration wrapper loaded from environment variables.
Config<T> reads environment variables and deserializes them into a
strongly-typed struct. Variable names are matched by converting struct field names
to SCREAMING_SNAKE_CASE.
Tuple Fields§
§0: TImplementations§
Source§impl<T> Config<T>where
T: DeserializeOwned + Clone,
impl<T> Config<T>where
T: DeserializeOwned + Clone,
Sourcepub fn from_env() -> Result<Config<T>, ConfigError>
pub fn from_env() -> Result<Config<T>, ConfigError>
Loads configuration from environment variables.
Field names are matched against environment variable names case-insensitively
(database_url ↔ DATABASE_URL). Non-string fields (u16, bool, …) are
parsed via the envy crate’s per-field deserializers, so a typed
port: u16 reads PORT=8080 natively without relying on JSON number
coercion (which the previous serde_json-roundtrip implementation got wrong).
Sourcepub fn from_env_prefixed(prefix: &str) -> Result<Config<T>, ConfigError>
pub fn from_env_prefixed(prefix: &str) -> Result<Config<T>, ConfigError>
Loads configuration from environment variables that share a common prefix.
Useful when several configs coexist in the process — set
MYAPP_DATABASE_URL, MYAPP_PORT, … and call Config::from_env_prefixed("MYAPP_").
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the wrapper and returns the inner value.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Config<T>where
T: Freeze,
impl<T> RefUnwindSafe for Config<T>where
T: RefUnwindSafe,
impl<T> Send for Config<T>where
T: Send,
impl<T> Sync for Config<T>where
T: Sync,
impl<T> Unpin for Config<T>where
T: Unpin,
impl<T> UnsafeUnpin for Config<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Config<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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