Macro evalexpr::context_map

source ·
macro_rules! context_map {
    ( ($ctx:expr) $k:expr => Function::new($($v:tt)*) ) => { ... };
    ( ($ctx:expr) $k:expr => $v:expr ) => { ... };
    ( ($ctx:expr) ) => { ... };
    ( ($ctx:expr) $k:expr => Function::new($($v:tt)*) , $($tt:tt)*) => { ... };
    ( ($ctx:expr) $k:expr => $v:expr , $($tt:tt)*) => { ... };
    ( $($tt:tt)* ) => { ... };
}
Expand description

This macro provides a convenient syntax for creating a static context.

Examples

use evalexpr::*;

let ctx = evalexpr::context_map! {
    "x" => 8,
    "f" => Function::new(|_| Ok(42.into()))
}.unwrap(); // Do proper error handling here

assert_eq!(eval_with_context("x + f()", &ctx), Ok(50.into()));