pub struct Callable<Args, R> { /* private fields */ }Expand description
Shares a callable whose borrowed arguments and owned result have fixed Rust types.
Every instantiation has exactly the canonical DynClosure representation.
Clones share execution state, not arguments or results. Recursive entry into
the same carrier returns an error; different carriers can call one another.
§Examples
use cel_runtime::Callable;
let f = Callable::from_fn(|x: &i32| Ok(*x));
assert_eq!(f.clone().call(&7).unwrap(), 7);Wrong Rust arguments cannot enter the body:
use cel_runtime::Callable;
let f = Callable::from_fn(|x: &i32| Ok(*x));
f.call(&"not an integer");Implementations§
Source§impl<Args: 'static, R: 'static> Callable<Args, R>
impl<Args: 'static, R: 'static> Callable<Args, R>
Sourcepub fn from_fn(f: fn(&Args) -> Result<R>) -> Self
pub fn from_fn(f: fn(&Args) -> Result<R>) -> Self
Shares a native function pointer with this exact borrowed/owned signature.
§Examples
See the module example.
Sourcepub fn from_prepared<A, Result>(body: PreparedSegment<A, Result>) -> Selfwhere
A: ArgumentList<Value = Args> + 'static,
Result: ValueRepr<Value = R> + 'static,
pub fn from_prepared<A, Result>(body: PreparedSegment<A, Result>) -> Selfwhere
A: ArgumentList<Value = Args> + 'static,
Result: ValueRepr<Value = R> + 'static,
Shares an independently prepared body with matching canonical arguments.
- Complexity: O(n) descriptor construction for n argument/result type nodes.
§Examples
use cel_runtime::{Callable, DynSegment, Nil, Leaf, CNil, EmptyList};
let mut body = DynSegment::new::<()>(); body.just(7i32);
let f = Callable::from_prepared(body.prepare::<Nil, Leaf<i32>>().unwrap());
assert_eq!(f.call(&CNil::<()>::root_empty()).unwrap(), 7);Sourcepub fn call(&self, args: &Args) -> Result<R>
pub fn call(&self, args: &Args) -> Result<R>
Borrows arguments and returns an independent result without checking signatures.
§Errors
Returns an error on reentrant entry into this shared carrier, or propagates the original body error. Errors and unwinding release the execution guard so later calls remain valid.
- Complexity: Body-dependent work; interpreted calls set up O(a) pointers for a arguments.
§Examples
See the module example.