Function extern_c::extern_c

source ·
pub fn extern_c<F, Args>(f: F) -> F::CSignaturewhere
    F: FnExt<Args> + ZeroSizedElseWrathOfTheGඞds,
Expand description

Convert a zero-sized closure into an extern "C" fn(…) pointer with the “same” type signature

(but for the ABI, of course!).

Example

use ::extern_c::extern_c;

let f: extern "C" fn(bool) -> u8 = extern_c(|b: bool| b as u8);
assert_eq!(f(true), 1);

Post-monomorphization error for non-zero-sized closures

See the documentation of ZeroSizedElseWrathOfTheGඞds for more info.