pub struct ShellEnvironment { /* private fields */ }
Expand description
Represents the shell variable environment, composed of a stack of scopes.
Implementations§
Source§impl ShellEnvironment
impl ShellEnvironment
Sourcepub fn push_scope(&mut self, scope_type: EnvironmentScope)
pub fn push_scope(&mut self, scope_type: EnvironmentScope)
Pushes a new scope of the given type onto the environment’s scope stack.
§Arguments
scope_type
- The type of scope to push.
Sourcepub fn pop_scope(
&mut self,
expected_scope_type: EnvironmentScope,
) -> Result<(), Error>
pub fn pop_scope( &mut self, expected_scope_type: EnvironmentScope, ) -> Result<(), Error>
Pops the top-most scope off the environment’s scope stack.
§Arguments
expected_scope_type
- The type of scope that is expected to be atop the stack.
Sourcepub fn iter_exported(&self) -> impl Iterator<Item = (&String, &ShellVariable)>
pub fn iter_exported(&self) -> impl Iterator<Item = (&String, &ShellVariable)>
Returns an iterator over all exported variables defined in the variable.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &ShellVariable)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &ShellVariable)>
Returns an iterator over all the variables defined in the environment.
Sourcepub fn iter_using_policy(
&self,
lookup_policy: EnvironmentLookup,
) -> impl Iterator<Item = (&String, &ShellVariable)>
pub fn iter_using_policy( &self, lookup_policy: EnvironmentLookup, ) -> impl Iterator<Item = (&String, &ShellVariable)>
Returns an iterator over all the variables defined in the environment, using the given lookup policy.
§Arguments
lookup_policy
- The policy to use when looking up variables.
Sourcepub fn get<S: AsRef<str>>(
&self,
name: S,
) -> Option<(EnvironmentScope, &ShellVariable)>
pub fn get<S: AsRef<str>>( &self, name: S, ) -> Option<(EnvironmentScope, &ShellVariable)>
Tries to retrieve an immutable reference to the variable with the given name in the environment.
§Arguments
name
- The name of the variable to retrieve.
Sourcepub fn get_mut<S: AsRef<str>>(
&mut self,
name: S,
) -> Option<(EnvironmentScope, &mut ShellVariable)>
pub fn get_mut<S: AsRef<str>>( &mut self, name: S, ) -> Option<(EnvironmentScope, &mut ShellVariable)>
Tries to retrieve a mutable reference to the variable with the given name in the environment.
§Arguments
name
- The name of the variable to retrieve.
Sourcepub fn get_str<S: AsRef<str>>(
&self,
name: S,
shell: &Shell,
) -> Option<Cow<'_, str>>
pub fn get_str<S: AsRef<str>>( &self, name: S, shell: &Shell, ) -> Option<Cow<'_, str>>
Tries to retrieve the string value of the variable with the given name in the environment.
§Arguments
name
- The name of the variable to retrieve.shell
- The shell owning the environment.
Sourcepub fn is_set<S: AsRef<str>>(&self, name: S) -> bool
pub fn is_set<S: AsRef<str>>(&self, name: S) -> bool
Checks if a variable of the given name is set in the environment.
§Arguments
name
- The name of the variable to check.
Sourcepub fn unset(&mut self, name: &str) -> Result<Option<ShellVariable>, Error>
pub fn unset(&mut self, name: &str) -> Result<Option<ShellVariable>, Error>
Tries to unset the variable with the given name in the environment, returning whether or not such a variable existed.
§Arguments
name
- The name of the variable to unset.
Sourcepub fn unset_index(&mut self, name: &str, index: &str) -> Result<bool, Error>
pub fn unset_index(&mut self, name: &str, index: &str) -> Result<bool, Error>
Tries to unset an array element from the environment, using the given name and element index for lookup. Returns whether or not an element was unset.
§Arguments
name
- The name of the array variable to unset an element from.index
- The index of the element to unset.
Sourcepub fn get_using_policy<N: AsRef<str>>(
&self,
name: N,
lookup_policy: EnvironmentLookup,
) -> Option<&ShellVariable>
pub fn get_using_policy<N: AsRef<str>>( &self, name: N, lookup_policy: EnvironmentLookup, ) -> Option<&ShellVariable>
Tries to retrieve an immutable reference to a variable from the environment, using the given name and lookup policy.
§Arguments
name
- The name of the variable to retrieve.lookup_policy
- The policy to use when looking up the variable.
Sourcepub fn get_mut_using_policy<N: AsRef<str>>(
&mut self,
name: N,
lookup_policy: EnvironmentLookup,
) -> Option<&mut ShellVariable>
pub fn get_mut_using_policy<N: AsRef<str>>( &mut self, name: N, lookup_policy: EnvironmentLookup, ) -> Option<&mut ShellVariable>
Tries to retrieve a mutable reference to a variable from the environment, using the given name and lookup policy.
§Arguments
name
- The name of the variable to retrieve.lookup_policy
- The policy to use when looking up the variable.
Sourcepub fn update_or_add<N: Into<String>>(
&mut self,
name: N,
value: ShellValueLiteral,
updater: impl Fn(&mut ShellVariable) -> Result<(), Error>,
lookup_policy: EnvironmentLookup,
scope_if_creating: EnvironmentScope,
) -> Result<(), Error>
pub fn update_or_add<N: Into<String>>( &mut self, name: N, value: ShellValueLiteral, updater: impl Fn(&mut ShellVariable) -> Result<(), Error>, lookup_policy: EnvironmentLookup, scope_if_creating: EnvironmentScope, ) -> Result<(), Error>
Update a variable in the environment, or add it if it doesn’t already exist.
§Arguments
name
- The name of the variable to update or add.value
- The value to assign to the variable.updater
- A function to call to update the variable after assigning the value.lookup_policy
- The policy to use when looking up the variable.scope_if_creating
- The scope to create the variable in if it doesn’t already exist.
Sourcepub fn update_or_add_array_element<N: Into<String>>(
&mut self,
name: N,
index: String,
value: String,
updater: impl Fn(&mut ShellVariable) -> Result<(), Error>,
lookup_policy: EnvironmentLookup,
scope_if_creating: EnvironmentScope,
) -> Result<(), Error>
pub fn update_or_add_array_element<N: Into<String>>( &mut self, name: N, index: String, value: String, updater: impl Fn(&mut ShellVariable) -> Result<(), Error>, lookup_policy: EnvironmentLookup, scope_if_creating: EnvironmentScope, ) -> Result<(), Error>
Update an array element in the environment, or add it if it doesn’t already exist.
§Arguments
name
- The name of the variable to update or add.index
- The index of the element to update or add.value
- The value to assign to the variable.updater
- A function to call to update the variable after assigning the value.lookup_policy
- The policy to use when looking up the variable.scope_if_creating
- The scope to create the variable in if it doesn’t already exist.
Sourcepub fn add<N: Into<String>>(
&mut self,
name: N,
var: ShellVariable,
target_scope: EnvironmentScope,
) -> Result<(), Error>
pub fn add<N: Into<String>>( &mut self, name: N, var: ShellVariable, target_scope: EnvironmentScope, ) -> Result<(), Error>
Adds a variable to the environment.
§Arguments
name
- The name of the variable to add.var
- The variable to add.target_scope
- The scope to add the variable to.
Sourcepub fn set_global<N: Into<String>>(
&mut self,
name: N,
var: ShellVariable,
) -> Result<(), Error>
pub fn set_global<N: Into<String>>( &mut self, name: N, var: ShellVariable, ) -> Result<(), Error>
Sets a global variable in the environment.
§Arguments
name
- The name of the variable to set.var
- The variable to set.
Trait Implementations§
Source§impl Clone for ShellEnvironment
impl Clone for ShellEnvironment
Source§fn clone(&self) -> ShellEnvironment
fn clone(&self) -> ShellEnvironment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ShellEnvironment
impl Debug for ShellEnvironment
Auto Trait Implementations§
impl Freeze for ShellEnvironment
impl RefUnwindSafe for ShellEnvironment
impl Send for ShellEnvironment
impl Sync for ShellEnvironment
impl Unpin for ShellEnvironment
impl UnwindSafe for ShellEnvironment
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> 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>
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