Trait FunctionDecl

Source
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§

Source

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§

Source

fn arguments() -> Vec<ValueType>

Get the argument types of the function.

Returns a vector of ValueType representing the expected argument types in the order they should be provided to the function.

§Returns

A vector of ValueType values representing each parameter type.

Source

fn result() -> ValueType

Get the return type of the function.

Returns the ValueType that this function signature returns.

§Returns

The ValueType representing the function’s return type.

Provided Methods§

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl<R> FunctionDecl for fn() -> R
where R: IntoResult,

Source§

impl<R, A1> FunctionDecl for fn(A1) -> R
where R: IntoResult, A1: TypedValue,

Source§

impl<R, A1, A2> FunctionDecl for fn(A1, A2) -> R
where R: IntoResult, A1: TypedValue, A2: TypedValue,

Source§

impl<R, A1, A2, A3> FunctionDecl for fn(A1, A2, A3) -> R
where R: IntoResult, A1: TypedValue, A2: TypedValue, A3: TypedValue,

Source§

impl<R, A1, A2, A3, A4> FunctionDecl for fn(A1, A2, A3, A4) -> R
where R: IntoResult, A1: TypedValue, A2: TypedValue, A3: TypedValue, A4: TypedValue,

Source§

impl<R, A1, A2, A3, A4, A5> FunctionDecl for fn(A1, A2, A3, A4, A5) -> R
where R: IntoResult, A1: TypedValue, A2: TypedValue, A3: TypedValue, A4: TypedValue, A5: TypedValue,

Source§

impl<R, A1, A2, A3, A4, A5, A6> FunctionDecl for fn(A1, A2, A3, A4, A5, A6) -> R

Source§

impl<R, A1, A2, A3, A4, A5, A6, A7> FunctionDecl for fn(A1, A2, A3, A4, A5, A6, A7) -> R

Source§

impl<R, A1, A2, A3, A4, A5, A6, A7, A8> FunctionDecl for fn(A1, A2, A3, A4, A5, A6, A7, A8) -> R

Source§

impl<R, A1, A2, A3, A4, A5, A6, A7, A8, A9> FunctionDecl for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> R

Source§

impl<R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> FunctionDecl for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> R

Implementors§