pub enum Variable {
Str(CString),
Array(Vec<(i64, CString)>),
Assoc(HashMap<CString, CString>),
}
Expand description
Contains the value of a shell variable.
Use find
or RawVariable::get
to get this value.
§Example
A function to print the value of var
.
use bash_builtins::variables::Variable;
use std::io::{self, Write};
fn print<W>(mut output: W, name: &str, var: &Variable) -> io::Result<()>
where
W: Write,
{
match var {
Variable::Str(s) => {
writeln!(output, "{} = {:?}", name, s)?;
}
Variable::Array(a) => {
for (idx, elem) in a.iter().enumerate() {
writeln!(&mut output, "{}[{}] = {:?}", name, idx, elem)?;
}
}
Variable::Assoc(a) => {
for (key, value) in a.iter() {
writeln!(&mut output, "{}[{:?}] = {:?}", name, key, value)?;
}
}
}
Ok(())
}
Variants§
Str(CString)
A single string.
Array(Vec<(i64, CString)>)
An indexed array.
Each element is a tuple with the index and the value of the items in the array.
Assoc(HashMap<CString, CString>)
An associative array.
These shell variables are initialized with declare -A
.
Trait Implementations§
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
Mutably borrows from an owned value. Read more