pub(super) struct Var<'env, 'lookup, T, C = fn(&'static str, T) -> Result<T>> {
lookup: &'lookup (dyn Fn(&str) -> Option<String> + 'env),
read_file: &'lookup (dyn Fn(&Path) -> Result<String> + 'env),
key: &'static str,
check: C,
aliases: Vec<&'static str>,
file_source: Option<FileSource>,
value: PhantomData<fn(T) -> T>,
}Expand description
Parses the first present key and validates its value in check order.
Checks may transform values and capture other settings. They receive the supplying key, including aliases. Defaults use the primary key and pass through the same checks. Missing optional values bypass parsing and checks.
Fields§
§lookup: &'lookup (dyn Fn(&str) -> Option<String> + 'env)§read_file: &'lookup (dyn Fn(&Path) -> Result<String> + 'env)§key: &'static str§check: C§aliases: Vec<&'static str>§file_source: Option<FileSource>§value: PhantomData<fn(T) -> T>Implementations§
Source§impl<'env, 'lookup, T, C> Var<'env, 'lookup, T, C>
impl<'env, 'lookup, T, C> Var<'env, 'lookup, T, C>
Sourcepub(super) fn check(
self,
check: impl Fn(&'static str, T) -> Result<T>,
) -> Var<'env, 'lookup, T, impl Fn(&'static str, T) -> Result<T>>
pub(super) fn check( self, check: impl Fn(&'static str, T) -> Result<T>, ) -> Var<'env, 'lookup, T, impl Fn(&'static str, T) -> Result<T>>
Appends a check that runs only after all preceding checks succeed.
pub(super) fn alias(self, alias: &'static str) -> Self
pub(super) fn or_load_from_file(self, alias: &'static str) -> Self
Sourcepub(super) fn exclusive_file(self, alias: &'static str) -> Self
pub(super) fn exclusive_file(self, alias: &'static str) -> Self
Loads the file only when no direct source is configured.
Reading a direct source together with this file source returns an
anyhow::Error without reading the file or disclosing the direct value.
Sourcepub(super) fn required(self) -> Result<T>
pub(super) fn required(self) -> Result<T>
Returns the parsed and checked value of the first present key.
§Errors
Returns anyhow::Error when every key is absent or parsing or a check fails.
Sourcepub(super) fn default(self, default: T) -> Result<T>
pub(super) fn default(self, default: T) -> Result<T>
Uses the typed default only when every key is absent.
§Errors
Returns anyhow::Error when parsing or a check fails, including checks
of the default value.
Sourcepub(super) fn optional(self) -> Result<Option<T>>
pub(super) fn optional(self) -> Result<Option<T>>
Returns None only when every key is absent.
§Errors
Returns anyhow::Error when parsing or a check of a present value fails.
fn load(&self) -> Result<Option<EnvValue>>
fn parse(&self, value: EnvValue) -> Result<T>
Auto Trait Implementations§
impl<'env, 'lookup, T, C> Freeze for Var<'env, 'lookup, T, C>where
C: Freeze,
impl<'env, 'lookup, T, C = fn(&'static str, T) -> Result<T, Error>> !RefUnwindSafe for Var<'env, 'lookup, T, C>
impl<'env, 'lookup, T, C = fn(&'static str, T) -> Result<T, Error>> !Send for Var<'env, 'lookup, T, C>
impl<'env, 'lookup, T, C = fn(&'static str, T) -> Result<T, Error>> !Sync for Var<'env, 'lookup, T, C>
impl<'env, 'lookup, T, C> Unpin for Var<'env, 'lookup, T, C>where
C: Unpin,
impl<'env, 'lookup, T, C> UnsafeUnpin for Var<'env, 'lookup, T, C>where
C: UnsafeUnpin,
impl<'env, 'lookup, T, C = fn(&'static str, T) -> Result<T, Error>> !UnwindSafe for Var<'env, 'lookup, T, C>
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<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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