Module decl

Source
Expand description

Function declaration trait for CEL expression evaluation.

This module provides the FunctionDecl trait for extracting compile-time type information from function signatures. The trait is used for function registration and type checking in CEL environments.

§Features

  • Compile-time type extraction: Extract argument and return types from function signatures
  • Sealed trait: Cannot be implemented outside this crate for type safety
  • Zero-annotation support: Works with standard Rust function types without annotations
  • Generic function support: Supports functions with 0 to 10 parameters
  • Type safety: Ensures only valid CEL-compatible function types can be declared

§Examples

§Basic function declaration

use cel_cxx::function::FunctionDecl;
use cel_cxx::types::ValueType;

// Extract type information from function signatures
type AddFn = fn(i64, i64) -> i64;
let arg_types = AddFn::arguments();
let return_type = AddFn::result();

assert_eq!(arg_types, vec![ValueType::Int, ValueType::Int]);
assert_eq!(return_type, ValueType::Int);

§Complex function types

// String processing function
type FormatFn = fn(String, i64) -> String;
let arg_types = FormatFn::arguments();
let return_type = FormatFn::result();

assert_eq!(arg_types, vec![ValueType::String, ValueType::Int]);
assert_eq!(return_type, ValueType::String);

§Zero-parameter functions

// Constant function
type PiFn = fn() -> f64;
let arg_types = PiFn::arguments();
let return_type = PiFn::result();

assert_eq!(arg_types, vec![]);
assert_eq!(return_type, ValueType::Double);

Traits§

FunctionDecl
Trait for extracting compile-time type information from function signatures.