extern_c/_lib.rs
1#![doc = include_str!("../README.md")]
2#![no_std]
3
4use helpers::ZeroSizedElseWrathOfTheGඞds;
5
6/// Convert a zero-sized closure into an `extern "C" fn(…)` pointer with the
7/// "same" type signature
8///
9/// (but for the ABI, of course!).
10///
11/// ## Example
12///
13/// ```rust
14/// use ::extern_c::extern_c;
15///
16/// let f: extern "C" fn(bool) -> u8 = extern_c(|b: bool| b as u8);
17/// assert_eq!(f(true), 1);
18/// ```
19///
20/// ### Post-monomorphization error for non-zero-sized closures
21///
22/// See the documentation of [`ZeroSizedElseWrathOfTheGඞds`] for more info.
23pub
24fn extern_c<F, Args>(f: F)
25 -> F::CSignature
26where
27 F : helpers::FnExt<Args>,
28 // for documentation purposes
29 F : ZeroSizedElseWrathOfTheGඞds,
30{
31 F::extern_c(f)
32}
33
34pub mod helpers;