filter_expr_evaler/
callable.rs

1use std::sync::Arc;
2
3use crate::{Error, FilterExprEvalerEnv, Value};
4
5/// The context for a function call.
6pub struct FunctionContext<'env, 'a> {
7    pub env: &'env FilterExprEvalerEnv,
8
9    pub args: &'a [Value],
10}
11
12/// The trait for a function.
13#[async_trait::async_trait]
14pub trait Function: Send + Sync {
15    /// Call the function.
16    async fn call(&self, ctx: FunctionContext<'_, '_>) -> Result<Value, Error>;
17}
18
19/// The boxed function.
20pub type ArcFunction = Arc<dyn Function>;
21
22/// The context for a method call.
23pub struct MethodContext<'env, 'a> {
24    pub env: &'env FilterExprEvalerEnv,
25
26    pub obj: &'a Value,
27    pub args: &'a [Value],
28}
29
30/// The trait for a method.
31#[async_trait::async_trait]
32pub trait Method: Send + Sync {
33    /// Call the method.
34    async fn call(&self, ctx: MethodContext<'_, '_>) -> Result<Value, Error>;
35}
36
37/// The boxed method.
38pub type ArcMethod = Arc<dyn Method>;