fn-ptr 0.1.0

A crate providing a function pointer trait.
Documentation

fn-ptr

CI crates.io Documentation dependency status MIT

A small Rust crate that exposes a FunctionPtr trait that is implemented for all function pointer types up to arity 12, for multiple calling conventions (ABIs). The trait looks like this:

pub trait FunctionPtr {
    const ARITY: usize;
    const SAFE: bool;
    const EXTERN: bool;
    const ABI: Abi;

    type Args;
    type Output;
}

Usage

fn print_info<F: fn_ptr::FunctionPtr>() {
    println!("arity = {}", F::ARITY);
    println!("safe = {}", F::SAFE);
    println!("extern = {}", F::EXTERN);
    println!("ABI = {:?}", F::ABI);
}

fn main() {
    print_info::<fn(i32) -> i32>();
    // Example output (typical):
    // arity = 1
    // safe = true
    // extern = false
    // ABI = Rust
    // example(10) = 11
}