pub trait FunctionExpression:
Send
+ Sync
+ Debug
+ DynClone
+ Clone
+ 'static {
// Required methods
fn resolve(&self, ctx: &mut Context<'_>) -> Resolved;
fn type_def(&self, state: &TypeState) -> TypeDef;
// Provided methods
fn as_value(&self) -> Option<Value> { ... }
fn as_expr(&self) -> Box<dyn Expression> { ... }
}
Expand description
A trait similar to Expression
, but simplified specifically for functions.
The main difference is this trait prevents mutation of variables both at runtime
and compile time.
Required Methods§
Sourcefn resolve(&self, ctx: &mut Context<'_>) -> Resolved
fn resolve(&self, ctx: &mut Context<'_>) -> Resolved
Resolves the function expression to a concrete Value
.
This method is executed at runtime.
An expression is allowed to fail, which aborts the running program.
§Arguments
ctx
- The context in which to resolve the expression.
§Returns
A Result
containing the resolved value or an error.
§Errors
Returns an error if the resolution fails.
Provided Methods§
Sourcefn as_value(&self) -> Option<Value>
fn as_value(&self) -> Option<Value>
Resolves values at compile-time for constant functions.
This returns Some
for constant expressions, or None
otherwise.
Sourcefn as_expr(&self) -> Box<dyn Expression>
fn as_expr(&self) -> Box<dyn Expression>
Converts this function to a normal Expression
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.