Trait IntoFunction

Source
pub trait IntoFunction<'f, Fm: FnMarker, Args = ()>: Sealed<Fm, Args> {
    // Required method
    fn into_function(self) -> Function<'f>;
}
Expand description

Trait for types that can be converted into function implementations.

This is the main entry point for function registration. Any Rust function or closure that meets the constraints can be converted into a Function.

§Type System Integration

The trait uses Rust’s type system to automatically:

  • Extract function signatures using FunctionDecl
  • Handle argument conversion using FromValue with GATs
  • Manage return type conversion using IntoResult
  • Support both synchronous and asynchronous functions

§Generic Associated Types (GATs)

This trait leverages GATs to handle complex lifetime relationships:

  • Functions returning &str can borrow from input parameters
  • Closures can capture environment variables with appropriate lifetimes
  • The system maintains memory safety through controlled lifetime erasure

§Note

This trait is sealed and cannot be implemented outside this crate.

§Type Parameters

  • 'f: Lifetime parameter for captured data in closures
  • Fm: Function marker (sync/async)
  • Args: Argument tuple type

§Examples

§Simple Functions

fn add(a: i64, b: i64) -> i64 { a + b }
fn divide(a: i64, b: i64) -> Result<f64, Infallible> {
    Ok(a as f64 / b as f64)
}

let add_func = add.into_function();
let div_func = divide.into_function();

§Closures with Captured Variables

let factor = 2.5;
let scale = move |x: f64| -> f64 { x * factor };
let scale_func = scale.into_function();

§Functions with Reference Parameters

fn process_text(text: &str, uppercase: bool) -> String {
    if uppercase { text.to_uppercase() } else { text.to_lowercase() }
}
let process_func = process_text.into_function();

Required Methods§

Source

fn into_function(self) -> Function<'f>

Convert this function into a type-erased implementation.

This method performs the conversion from a strongly-typed Rust function to a type-erased Function that can be called from CEL expressions.

§Returns

A Function that encapsulates the original function with:

  • Type-safe argument conversion
  • Return value conversion
  • Error handling
  • Async support (if applicable)
§Performance

The conversion is zero-cost at runtime. All type checking and conversion logic is generated at compile time.

Implementors§

Source§

impl<'f, F, Fut, R> IntoFunction<'f, Async> for F
where F: Fn() -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1> IntoFunction<'f, Async, (A1,)> for F
where F: Fn(A1) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2> IntoFunction<'f, Async, (A1, A2)> for F
where F: Fn(A1, A2) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3> IntoFunction<'f, Async, (A1, A2, A3)> for F
where F: Fn(A1, A2, A3) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4> IntoFunction<'f, Async, (A1, A2, A3, A4)> for F
where F: Fn(A1, A2, A3, A4) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5> IntoFunction<'f, Async, (A1, A2, A3, A4, A5)> for F
where F: Fn(A1, A2, A3, A4, A5) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6)> for F
where F: Fn(A1, A2, A3, A4, A5, A6) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6, A7> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6, A7)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6, A7, A8> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6, A7, A8)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6, A7, A8, A9> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6, A7, A8, A9)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f, A9: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> Fut + Send + Sync + 'f, Fut: Future<Output = R> + Send + 'f, R: IntoResult + Send + Sync + 'f, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f, A9: FromValue + TypedValue + Send + Sync + 'f, A10: FromValue + TypedValue + Send + Sync + 'f,

Available on crate feature async only.
Source§

impl<'f, F, R> IntoFunction<'f, ()> for F
where F: Fn() -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (): Arguments,

Source§

impl<'f, F, R, A1> IntoFunction<'f, (), (A1,)> for F
where F: Fn(A1) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1,): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2> IntoFunction<'f, (), (A1, A2)> for F
where F: Fn(A1, A2) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3> IntoFunction<'f, (), (A1, A2, A3)> for F
where F: Fn(A1, A2, A3) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4> IntoFunction<'f, (), (A1, A2, A3, A4)> for F
where F: Fn(A1, A2, A3, A4) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5> IntoFunction<'f, (), (A1, A2, A3, A4, A5)> for F
where F: Fn(A1, A2, A3, A4, A5) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5, A6> IntoFunction<'f, (), (A1, A2, A3, A4, A5, A6)> for F
where F: Fn(A1, A2, A3, A4, A5, A6) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5, A6): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5, A6, A7> IntoFunction<'f, (), (A1, A2, A3, A4, A5, A6, A7)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5, A6, A7): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5, A6, A7, A8> IntoFunction<'f, (), (A1, A2, A3, A4, A5, A6, A7, A8)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5, A6, A7, A8): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5, A6, A7, A8, A9> IntoFunction<'f, (), (A1, A2, A3, A4, A5, A6, A7, A8, A9)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5, A6, A7, A8, A9): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f, A9: FromValue + TypedValue + Send + Sync + 'f,

Source§

impl<'f, F, R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> IntoFunction<'f, (), (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> for F
where F: Fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> R + Send + Sync + 'f, R: IntoResult + Send + Sync + 'f, (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10): Arguments, A1: FromValue + TypedValue + Send + Sync + 'f, A2: FromValue + TypedValue + Send + Sync + 'f, A3: FromValue + TypedValue + Send + Sync + 'f, A4: FromValue + TypedValue + Send + Sync + 'f, A5: FromValue + TypedValue + Send + Sync + 'f, A6: FromValue + TypedValue + Send + Sync + 'f, A7: FromValue + TypedValue + Send + Sync + 'f, A8: FromValue + TypedValue + Send + Sync + 'f, A9: FromValue + TypedValue + Send + Sync + 'f, A10: FromValue + TypedValue + Send + Sync + 'f,