pub struct TypedEnvVar<T> { /* private fields */ }Expand description
A typed environment variable wrapper with caller-provided parsing.
Implementations§
Source§impl<T> TypedEnvVar<T>
impl<T> TypedEnvVar<T>
Sourcepub const fn new(name: EnvVarName) -> Self
pub const fn new(name: EnvVarName) -> Self
Creates a typed environment variable wrapper.
Sourcepub const fn name(&self) -> &EnvVarName
pub const fn name(&self) -> &EnvVarName
Returns the underlying environment variable name.
Sourcepub fn read_with<E>(
&self,
parser: impl FnOnce(&str) -> Result<T, E>,
) -> Result<T, TypedEnvVarError<E>>
pub fn read_with<E>( &self, parser: impl FnOnce(&str) -> Result<T, E>, ) -> Result<T, TypedEnvVarError<E>>
Reads and parses the environment variable with a caller-provided parser.
§Errors
Returns TypedEnvVarError::Read when the variable cannot be read and
TypedEnvVarError::Parse when the parser rejects the value.
Sourcepub fn read_parse(&self) -> Result<T, TypedEnvVarError<T::Err>>where
T: FromStr,
pub fn read_parse(&self) -> Result<T, TypedEnvVarError<T::Err>>where
T: FromStr,
Reads and parses the environment variable with FromStr.
§Errors
Returns TypedEnvVarError::Read when the variable cannot be read and
TypedEnvVarError::Parse when T::from_str rejects the value.
Trait Implementations§
Source§impl<T: Clone> Clone for TypedEnvVar<T>
impl<T: Clone> Clone for TypedEnvVar<T>
Source§fn clone(&self) -> TypedEnvVar<T>
fn clone(&self) -> TypedEnvVar<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for TypedEnvVar<T>
impl<T: Debug> Debug for TypedEnvVar<T>
Source§impl<T: PartialEq> PartialEq for TypedEnvVar<T>
impl<T: PartialEq> PartialEq for TypedEnvVar<T>
Source§fn eq(&self, other: &TypedEnvVar<T>) -> bool
fn eq(&self, other: &TypedEnvVar<T>) -> bool
Tests for
self and other values to be equal, and is used by ==.impl<T: Eq> Eq for TypedEnvVar<T>
impl<T> StructuralPartialEq for TypedEnvVar<T>
Auto Trait Implementations§
impl<T> Freeze for TypedEnvVar<T>
impl<T> RefUnwindSafe for TypedEnvVar<T>
impl<T> Send for TypedEnvVar<T>
impl<T> Sync for TypedEnvVar<T>
impl<T> Unpin for TypedEnvVar<T>
impl<T> UnsafeUnpin for TypedEnvVar<T>
impl<T> UnwindSafe for TypedEnvVar<T>
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