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 closuresFm
: 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§
Sourcefn into_function(self) -> Function<'f>
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§
impl<'f, F, Fut, R> IntoFunction<'f, Async> for F
async
only.impl<'f, F, Fut, R, A1> IntoFunction<'f, Async, (A1,)> for F
async
only.impl<'f, F, Fut, R, A1, A2> IntoFunction<'f, Async, (A1, A2)> for F
async
only.impl<'f, F, Fut, R, A1, A2, A3> IntoFunction<'f, Async, (A1, A2, A3)> for Fwhere
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,
async
only.impl<'f, F, Fut, R, A1, A2, A3, A4> IntoFunction<'f, Async, (A1, A2, A3, A4)> for Fwhere
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,
async
only.impl<'f, F, Fut, R, A1, A2, A3, A4, A5> IntoFunction<'f, Async, (A1, A2, A3, A4, A5)> for Fwhere
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,
async
only.impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6)> for Fwhere
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,
async
only.impl<'f, F, Fut, R, A1, A2, A3, A4, A5, A6, A7> IntoFunction<'f, Async, (A1, A2, A3, A4, A5, A6, A7)> for Fwhere
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,
async
only.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 Fwhere
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,
async
only.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 Fwhere
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,
async
only.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 Fwhere
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,
async
only.