pub struct EnvironmentSpec { /* private fields */ }Expand description
Environment construction rules for a command.
Overrides are kept in a sorted map for deterministic inspection and are
applied by a backend after selecting the requested base environment. A
value of EnvironmentOverride::Remove is distinct from setting an empty
string. Variable names are one logical, case-insensitive namespace, so a
later case variant replaces an earlier override.
Implementations§
Source§impl EnvironmentSpec
impl EnvironmentSpec
Sourcepub fn inherit_all() -> Self
pub fn inherit_all() -> Self
Creates an environment that inherits all parent variables.
Sourcepub fn inherit_core() -> Self
pub fn inherit_core() -> Self
Creates an environment that inherits the platform’s core variables.
Sourcepub fn base(&self) -> EnvironmentBase
pub fn base(&self) -> EnvironmentBase
Returns the selected base environment behavior.
Sourcepub fn overrides(&self) -> &BTreeMap<OsString, EnvironmentOverride>
pub fn overrides(&self) -> &BTreeMap<OsString, EnvironmentOverride>
Returns all explicit variable overrides in deterministic key order.
The spelling of a name is retained for backend diagnostics, but names are one case-insensitive logical namespace for lookup and equality.
Sourcepub fn filters(&self) -> &BTreeMap<EnvironmentPattern, EnvironmentFilterAction>
pub fn filters(&self) -> &BTreeMap<EnvironmentPattern, EnvironmentFilterAction>
Returns canonical environment filters in deterministic pattern order.
Sourcepub fn override_for(&self, name: &OsStr) -> Option<&EnvironmentOverride>
pub fn override_for(&self, name: &OsStr) -> Option<&EnvironmentOverride>
Returns the override for one variable, if present.
Sourcepub fn filter_action_for(&self, name: &str) -> Option<EnvironmentFilterAction>
pub fn filter_action_for(&self, name: &str) -> Option<EnvironmentFilterAction>
Returns the filter action for a variable name, if a filter matches.
Exclude always wins when both actions match. A backend can use the presence of any include filter together with this result to implement the complete inherited-environment decision without reimplementing wildcard precedence.
Sourcepub fn apply_to(
&self,
input: EnvironmentInput,
) -> Result<EnvironmentInput, CommandError>
pub fn apply_to( &self, input: EnvironmentInput, ) -> Result<EnvironmentInput, CommandError>
Applies filters and explicit overrides to an already selected base environment.
The caller selects the All, Core, or None base at the backend
boundary. A broader input is rejected before transformation. This
method then applies the portable sequence exclude -> set/remove -> include and keeps the validated base tag on the returned snapshot. A
variable removed by an exclude is not restored by an include; an
explicit set is applied after exclusion and can intentionally
reintroduce that named variable.
Sourcepub fn with_var(
self,
name: impl Into<OsString>,
value: impl Into<OsString>,
) -> Result<Self, CommandError>
pub fn with_var( self, name: impl Into<OsString>, value: impl Into<OsString>, ) -> Result<Self, CommandError>
Adds a variable assignment and returns the updated environment.
Sourcepub fn without_var(
self,
name: impl Into<OsString>,
) -> Result<Self, CommandError>
pub fn without_var( self, name: impl Into<OsString>, ) -> Result<Self, CommandError>
Adds a variable removal and returns the updated environment.
Sourcepub fn with_filter(
self,
pattern: impl Into<String>,
action: EnvironmentFilterAction,
) -> Result<Self, CommandError>
pub fn with_filter( self, pattern: impl Into<String>, action: EnvironmentFilterAction, ) -> Result<Self, CommandError>
Adds or replaces a canonical environment filter.
Sourcepub fn with_include_pattern(
self,
pattern: impl Into<String>,
) -> Result<Self, CommandError>
pub fn with_include_pattern( self, pattern: impl Into<String>, ) -> Result<Self, CommandError>
Adds an include filter.
Sourcepub fn with_exclude_pattern(
self,
pattern: impl Into<String>,
) -> Result<Self, CommandError>
pub fn with_exclude_pattern( self, pattern: impl Into<String>, ) -> Result<Self, CommandError>
Adds an exclude filter.