Enum bash_builtins::variables::Variable
source · [−]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<CString>)
An indexed array.
Assoc(HashMap<CString, CString>)
An associative array.
These shell variables are initialized with declare -A
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnwindSafe for Variable
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more