ShellEnvironment

Struct ShellEnvironment 

Source
pub struct ShellEnvironment { /* private fields */ }
Expand description

Represents the shell variable environment, composed of a stack of scopes.

Implementations§

Source§

impl ShellEnvironment

Source

pub fn new() -> Self

Returns a new shell environment.

Source

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.
Source

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.
Source

pub fn iter_exported(&self) -> impl Iterator<Item = (&String, &ShellVariable)>

Returns an iterator over all exported variables defined in the variable.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &ShellVariable)>

Returns an iterator over all the variables defined in the environment.

Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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

Source§

fn clone(&self) -> ShellEnvironment

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ShellEnvironment

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ShellEnvironment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more