pub struct ExpressionFunction {
pub name: String,
pub params: Vec<String>,
pub expression: String,
pub compiled_ast: AstExpr,
pub description: Option<String>,
}
Expand description
Represents a function defined by an expression string rather than Rust code.
Expression functions allow users to define custom functions using the expression language itself. These functions are compiled once when registered and can be called from other expressions. They support parameters and can access variables from the evaluation context.
§Example
let mut ctx = EvalContext::new();
// Register a function to calculate the area of a circle
ctx.register_expression_function(
"circle_area", // Function name
&["radius"], // Parameter names
"pi * radius * radius" // Function body as an expression
).unwrap();
// Use the function in another expression
let result = interp("circle_area(2)", Some(Rc::new(ctx))).unwrap();
assert!(result > 12.56 && result < 12.57); // π * 4 ≈ 12.566
Fields§
§name: String
The name of the function as it will be used in expressions.
params: Vec<String>
The parameter names that the function accepts.
expression: String
The original expression string defining the function body.
compiled_ast: AstExpr
The pre-compiled AST of the expression for faster evaluation.
description: Option<String>
Optional description of what the function does.
Trait Implementations§
Source§impl Clone for ExpressionFunction
impl Clone for ExpressionFunction
Source§fn clone(&self) -> ExpressionFunction
fn clone(&self) -> ExpressionFunction
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ExpressionFunction
impl RefUnwindSafe for ExpressionFunction
impl Send for ExpressionFunction
impl Sync for ExpressionFunction
impl Unpin for ExpressionFunction
impl UnwindSafe for ExpressionFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more