pub struct Env { /* private fields */ }Expand description
The resolved environment for one process run: the home-derived paths plus a
snapshot of the process environment variables. Built once via
Env::from_process and passed down by reference (or Arc) rather than
re-read on demand.
Implementations§
Source§impl Env
impl Env
Sourcepub fn from_process() -> Self
pub fn from_process() -> Self
Capture the real process environment: the home directory and a snapshot
of all environment variables. The single point where production reads
std::env and dirs::home_dir.
Sourcepub fn for_test(home: impl Into<PathBuf>) -> Self
pub fn for_test(home: impl Into<PathBuf>) -> Self
A test environment rooted at home with no environment variables. Add
variables with Env::with_var.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
An environment with neither a home directory nor variables. Models the
rare case where dirs::home_dir() returns None.
Sourcepub fn with_var(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with_var(self, key: impl Into<String>, value: impl Into<String>) -> Self
Builder: set a variable. Chainable, for test construction.
Sourcepub fn paths(&self) -> Option<&Paths>
pub fn paths(&self) -> Option<&Paths>
Home-derived paths, or None when the home directory is unknown.
Sourcepub fn var(&self, key: &str) -> Option<&str>
pub fn var(&self, key: &str) -> Option<&str>
Raw lookup of an arbitrary variable. Used by SSH config ${VAR}
expansion, which references user-chosen names.
Sourcepub fn vault_addr(&self) -> Option<&str>
pub fn vault_addr(&self) -> Option<&str>
VAULT_ADDR fallback for Vault SSH address resolution.
Sourcepub fn aws_credentials(&self) -> Option<(&str, &str)>
pub fn aws_credentials(&self) -> Option<(&str, &str)>
(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) when both are set.
Sourcepub fn purple_token(&self) -> Option<&str>
pub fn purple_token(&self) -> Option<&str>
PURPLE_TOKEN, the self-invocation auth token.
Sourcepub fn no_color(&self) -> bool
pub fn no_color(&self) -> bool
True when NO_COLOR is present (any value), per the no-color convention.
Sourcepub fn term_program(&self) -> Option<&str>
pub fn term_program(&self) -> Option<&str>
TERM_PROGRAM.
Sourcepub fn active_proxy_vars(&self) -> Vec<&'static str>
pub fn active_proxy_vars(&self) -> Vec<&'static str>
Proxy-related variable names that are set to a non-empty value, in a stable order. Drives the startup banner’s proxy summary.
Sourcepub fn command(&self, program: &str) -> Command
pub fn command(&self, program: &str) -> Command
Build a Command for program whose environment is exactly this Env’s
snapshot. In production the snapshot is the full process environment
captured at startup, so the subprocess sees the same env it would have
inherited. Tests construct an Env with only the vars they care about
(e.g. a stub-binary PATH), so subprocess resolution and env-dependent
behaviour are controlled without mutating the process-global env (no
unsafe set_var, no lock).
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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