Skip to main content

Env

Struct Env 

Source
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

Source

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.

Source

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.

Source

pub fn empty() -> Self

An environment with neither a home directory nor variables. Models the rare case where dirs::home_dir() returns None.

Source

pub fn with_var(self, key: impl Into<String>, value: impl Into<String>) -> Self

Builder: set a variable. Chainable, for test construction.

Source

pub fn paths(&self) -> Option<&Paths>

Home-derived paths, or None when the home directory is unknown.

Source

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.

Source

pub fn vault_addr(&self) -> Option<&str>

VAULT_ADDR fallback for Vault SSH address resolution.

Source

pub fn aws_credentials(&self) -> Option<(&str, &str)>

(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) when both are set.

Source

pub fn purple_token(&self) -> Option<&str>

PURPLE_TOKEN, the self-invocation auth token.

Source

pub fn no_color(&self) -> bool

True when NO_COLOR is present (any value), per the no-color convention.

Source

pub fn colorterm(&self) -> Option<&str>

COLORTERM.

Source

pub fn term_program(&self) -> Option<&str>

TERM_PROGRAM.

Source

pub fn term(&self) -> Option<&str>

TERM.

Source

pub fn in_tmux(&self) -> bool

True when running inside tmux (TMUX is set).

Source

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.

Source

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§

Source§

impl Clone for Env

Source§

fn clone(&self) -> Env

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Env

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V