pub struct Variable {
pub value: Option<Value>,
pub last_assigned_location: Option<Location>,
pub is_exported: bool,
pub read_only_location: Option<Location>,
pub quirk: Option<Quirk>,
}Expand description
Definition of a variable.
The methods of Variable are designed to be used in a method chain,
but you usually don’t create a Variable instance directly.
Instead, use VariableSet::get_or_new or
Env::get_or_create_variable to
create a variable in a variable set and obtain a mutable reference to it
(VariableRefMut), which allows you to modify the variable.
Fields§
§value: Option<Value>Value of the variable.
The value is None if the variable has been declared without
assignment.
last_assigned_location: Option<Location>Optional location where this variable was assigned.
If the current variable value originates from an assignment performed in
the shell session, last_assigned_location is the location of the
assignment. Otherwise, last_assigned_location is None.
is_exported: boolWhether this variable is exported or not.
An exported variable is also referred to as an environment variable.
read_only_location: Option<Location>Optional location where this variable was made read-only.
If this variable is not read-only, read_only_location is None.
Otherwise, read_only_location is the location of the simple command
that executed the readonly built-in that made this variable read-only.
quirk: Option<Quirk>Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new<S: Into<String>>(value: S) -> Self
pub fn new<S: Into<String>>(value: S) -> Self
Creates a new scalar variable from a string.
The returned variable’s last_assigned_location and
read_only_location are None and is_exported is false.
Sourcepub fn new_array<I, S>(values: I) -> Self
pub fn new_array<I, S>(values: I) -> Self
Creates a new array variable from a string.
The returned variable’s last_assigned_location and
read_only_location are None and is_exported is false.
Sourcepub fn new_empty_array() -> Self
pub fn new_empty_array() -> Self
Creates a new empty array variable.
The returned variable’s last_assigned_location and
read_only_location are None and is_exported is false.
Sourcepub fn set_assigned_location(self, location: Location) -> Self
pub fn set_assigned_location(self, location: Location) -> Self
Sets the last assigned location.
This is a convenience function for doing
self.last_assigned_location = Some(location) in a method chain.
Sourcepub fn export(self) -> Self
pub fn export(self) -> Self
Sets the is_exported flag.
This is a convenience function for doing self.is_exported = true in a
method chain.
Sourcepub fn make_read_only(self, location: Location) -> Self
pub fn make_read_only(self, location: Location) -> Self
Makes the variable read-only.
This is a convenience function for doing
self.read_only_location = Some(location) in a method chain.
Sourcepub const fn is_read_only(&self) -> bool
pub const fn is_read_only(&self) -> bool
Whether this variable is read-only or not.
Sourcepub fn expand(&self, location: &Location) -> Expansion<'_>
pub fn expand(&self, location: &Location) -> Expansion<'_>
Returns the value of this variable, applying any quirk.
If this variable has no Quirk, this function just returns
self.value converted to Expansion. Otherwise, the effect of the
quirk is applied to the value and the result is returned.
This function requires the location of the parameter expanding this
variable, so that Quirk::LineNumber can yield the line number of the
location.
Trait Implementations§
Source§impl<'a> From<&'a mut Variable> for VariableRefMut<'a>
impl<'a> From<&'a mut Variable> for VariableRefMut<'a>
impl Eq for Variable
impl StructuralPartialEq for Variable
Auto Trait Implementations§
impl Freeze for Variable
impl !RefUnwindSafe for Variable
impl !Send for Variable
impl !Sync for Variable
impl Unpin for Variable
impl !UnwindSafe for Variable
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