pub fn safe_eval(input: &str) -> Result<VecDeque<f64>, EvaluationError>
Expand description

safe_eval takes a &str evaluates the expression, returning the resulting stack as a Result if the expression is valid, or an Err if the expression is invalid or otherwise cannot be evaluated.

safe_eval is useful for testing the validity of an expression, and is safer than eval, as it does not mutate any inputted values.

Examples

use dc-ock::safe_eval;

fn main() {
    let expr = "1 2 +";
    match safe_eval(expr) {
        Ok(x) => println!("{:?}", x), // prints [3.0]
        Err(e) => println!("{}", e),  // prints an error message
    }
}