Enum bash_builtins::variables::Variable[][src]

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

A single string.

Tuple Fields of Str

0: CString
Array

An indexed array.

Tuple Fields of Array

0: Vec<CString>
Assoc

An associative array.

These shell variables are initialized with declare -A.

Tuple Fields of Assoc

0: HashMap<CString, CString>

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.