ein_ffi/
closure.rs

1use std::os::raw::c_void;
2
3#[repr(C)]
4#[derive(Clone)]
5pub struct Closure {
6    entry_pointer: *const c_void,
7    drop_function: extern "C" fn(*mut u8),
8    arity: usize,
9}
10
11impl Closure {
12    pub fn new(entry_pointer: *const c_void, arity: usize) -> Self {
13        Self {
14            entry_pointer,
15            drop_function: drop_nothing,
16            arity,
17        }
18    }
19}
20
21extern "C" fn drop_nothing(_: *mut u8) {}
22
23unsafe impl Sync for Closure {}
24
25impl Drop for Closure {
26    fn drop(&mut self) {
27        let drop = self.drop_function;
28
29        drop(self as *mut Self as *mut u8);
30    }
31}