pub struct ExpressionFunction {
pub name: FunctionName,
pub params: Vec<String>,
pub expression: String,
pub description: Option<String>,
pub param_buffer: Option<*mut [(HString, Real)]>,
}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();
// Note: Expression functions require runtime parsing which is not supported
// in the current arena-based architecture. Use native functions instead:
ctx.register_native_function("circle_area", 1, |args| {
let radius = args[0];
std::f64::consts::PI * radius * radius
}).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.566Fields§
§name: FunctionNameThe name of the function as it will be used in expressions.
params: Vec<String>The parameter names that the function accepts.
expression: StringThe original expression string defining the function body.
description: Option<String>Optional description of what the function does.
param_buffer: Option<*mut [(HString, Real)]>Pre-allocated parameter buffer for zero-allocation evaluation. When available, this points to an arena-allocated slice that can be reused for every function call instead of allocating new parameter storage. The slice size matches params.len() and gets filled with actual values during evaluation.
Trait Implementations§
Auto 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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)