Skip to main content

Callable

Struct Callable 

Source
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, R> Callable<Args, R>
where Args: 'static, R: 'static,

Source

pub fn from_fn(f: fn(&Args) -> Result<R, Error>) -> Callable<Args, R>

Shares a native function pointer with this exact borrowed/owned signature.

§Examples

See the module example.

Source

pub fn from_prepared<A, Result>( body: PreparedSegment<A, Result>, ) -> Callable<Args, R>
where 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);
Source

pub fn call(&self, args: &Args) -> Result<R, Error>

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.

Trait Implementations§

Source§

impl<Args, R> Clone for Callable<Args, R>

Source§

fn clone(&self) -> Callable<Args, R>

Shares the carrier without imposing clone bounds on the signature.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Args, R> !RefUnwindSafe for Callable<Args, R>

§

impl<Args, R> !Send for Callable<Args, R>

§

impl<Args, R> !Sync for Callable<Args, R>

§

impl<Args, R> !UnwindSafe for Callable<Args, R>

§

impl<Args, R> Freeze for Callable<Args, R>

§

impl<Args, R> Unpin for Callable<Args, R>

§

impl<Args, R> UnsafeUnpin for Callable<Args, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.