pub struct Env(/* private fields */);Expand description
Environment variable abstraction
Environment variables are global to a process, and, as such, are difficult to test with a multi-
threaded test runner like Rust’s. This enables loading environment variables either from the
actual process environment (std::env::var) or from a hash map.
Process environments are cheap to clone:
- Faked process environments are wrapped in an internal Arc
- Real process environments are pointer-sized
Implementations§
Source§impl Env
impl Env
Sourcepub fn get(&self, k: &str) -> Result<String, VarError>
pub fn get(&self, k: &str) -> Result<String, VarError>
Retrieve a value for the given k and return VarError is that key is not present.
Sourcepub fn from_slice<'a>(vars: &[(&'a str, &'a str)]) -> Self
pub fn from_slice<'a>(vars: &[(&'a str, &'a str)]) -> Self
Create a fake process environment from a slice of tuples.
§Examples
use aws_types::os_shim_internal::Env;
let mock_env = Env::from_slice(&[
("HOME", "/home/myname"),
("AWS_REGION", "us-west-2")
]);
assert_eq!(mock_env.get("HOME").unwrap(), "/home/myname");Sourcepub fn real() -> Self
pub fn real() -> Self
Create a process environment that uses the real process environment
Calls will be delegated to std::env::var.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Env
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
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<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 moreCreates a shared type from an unshared type.