Enum bash_builtins::variables::Variable
source · pub enum Variable {
Str(CString),
Array(Vec<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<CString>)
An indexed array.
Assoc(HashMap<CString, CString>)
An associative array.
These shell variables are initialized with declare -A
.