Crate expression_macro

Source
Expand description

§Expression Macro

This crate provides procedural macros for creating mathematical expressions at compile time. It serves as a companion to the expression_core crate, providing syntactic sugar and compile-time validation for mathematical expressions.

§Benefits of Compile-Time Expression Parsing

  • Early Error Detection: Syntax errors in expressions are caught at compile time
  • Performance Optimization: Parsing happens during compilation rather than at runtime
  • Type Safety: Ensures expressions are well-formed before execution

§Usage

use expression_macro::expr;
use std::collections::HashMap;

let expr = expr!("x^2 + y^2");

let mut vars = HashMap::new();
vars.insert("x".to_string(), 3.0);
vars.insert("y".to_string(), 4.0);

let result = expr.evaluate(&vars).unwrap();
assert_eq!(result, 25.0);

Macros§

expr
Creates an expression at compile time.