#abi #callback #extern

extern-c

Convert a zero-sized closure into an extern "C" fn() pointer

2 releases

0.1.1-rc1 Sep 7, 2023
0.1.0 Sep 5, 2023

#2760 in Rust patterns

Download history 7700/week @ 2024-07-20 6758/week @ 2024-07-27 5216/week @ 2024-08-03 5271/week @ 2024-08-10 7248/week @ 2024-08-17 5901/week @ 2024-08-24 7223/week @ 2024-08-31 6242/week @ 2024-09-07 4923/week @ 2024-09-14 8517/week @ 2024-09-21 7445/week @ 2024-09-28 9654/week @ 2024-10-05 11919/week @ 2024-10-12 11968/week @ 2024-10-19 10214/week @ 2024-10-26 10926/week @ 2024-11-02

46,036 downloads per month
Used in 32 crates (2 directly)

Zlib OR MIT OR Apache-2.0

13KB
175 lines

::extern-c

Convert a zero-sized closure into an extern "C" fn() pointer with the same[^abi] type signature.

[^abi]: but for the ABI, of course!

Repository Latest version Documentation MSRV no_std compatible License CI

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);

Dependencies

~8KB