pub trait FunctionDecl: Sealed {
const ARGUMENTS_LEN: usize;
// Required methods
fn arguments() -> Vec<ValueType>;
fn result() -> ValueType;
// Provided methods
fn function_type() -> FunctionType { ... }
fn arguments_len() -> usize { ... }
}
Expand description
Trait for extracting compile-time type information from function signatures.
This trait provides static methods to extract argument and return type information from function pointer types. It is used purely for type declarations and does not require the ability to instantiate values, only to determine their types.
§Note
This trait is sealed and cannot be implemented outside this crate. It is automatically implemented for function pointer types with compatible signatures.
§Automatically Implemented For
The trait is implemented for function pointer types:
fn() -> R
fn(A1) -> R
fn(A1, A2) -> R
fn(A1, A2, A3) -> R
- … (up to 10 arguments)
Where:
R: TypedValue
(return type must have a known CEL type)A1, A2, ...: TypedValue
(argument types must have known CEL types)
§Examples
// Simple arithmetic function
type MathFn = fn(i64, i64) -> i64;
assert_eq!(MathFn::arguments(), vec![ValueType::Int, ValueType::Int]);
assert_eq!(MathFn::result(), ValueType::Int);
// String manipulation function
type StringFn = fn(String, i64) -> String;
assert_eq!(StringFn::arguments(), vec![ValueType::String, ValueType::Int]);
assert_eq!(StringFn::result(), ValueType::String);
Required Associated Constants§
Sourceconst ARGUMENTS_LEN: usize
const ARGUMENTS_LEN: usize
The number of arguments that this function signature accepts.
This constant provides compile-time access to the arity (number of parameters)
of the function signature. It is automatically computed by the implementation
and matches the length of the vector returned by arguments()
.
§Examples
type NoArgsFn = fn() -> i64;
type TwoArgsFn = fn(i64, String) -> bool;
type ThreeArgsFn = fn(i64, String, bool) -> f64;
assert_eq!(NoArgsFn::ARGUMENTS_LEN, 0);
assert_eq!(TwoArgsFn::ARGUMENTS_LEN, 2);
assert_eq!(ThreeArgsFn::ARGUMENTS_LEN, 3);
Required Methods§
Provided Methods§
Sourcefn function_type() -> FunctionType
fn function_type() -> FunctionType
Get the function type of the function.
Returns the FunctionType
that this function signature represents.
§Returns
The FunctionType
is a tuple of the return type and the argument types.
Sourcefn arguments_len() -> usize
fn arguments_len() -> usize
Get the number of arguments of the function.
Returns the number of arguments that the function takes.
§Returns
The number of arguments that the function takes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.