teo_runtime/struct/function/
instance_function.rs

1use educe::Educe;
2use std::sync::Arc;
3use serde::Serialize;
4use crate::arguments::Arguments;
5use teo_result::Result;
6use crate::value::Value;
7
8#[derive(Educe, Serialize, Clone)]
9#[educe(Debug)]
10pub struct Definition {
11    pub path: Vec<String>,
12    #[educe(Debug(ignore))] #[serde(skip)]
13    pub body: Arc<dyn Function>,
14}
15
16pub trait Function: Send + Sync {
17    fn call(&self, this: Value, arguments: Arguments) -> Result<Value>;
18}
19
20impl<F> Function for F where
21    F: Fn(Value, Arguments) -> Result<Value> + Send + Sync {
22    fn call(&self, this: Value, arguments: Arguments) -> Result<Value> {
23        self(this, arguments)
24    }
25}
26