1 //! Closure type (equivalent to `&mut dyn FnMut(A) -> R`) that's `repr(C)`.
4 pub struct Closure<'a, A, R> {
5 call: unsafe extern "C" fn(&mut Env, A) -> R,
13 impl<'a, A, R> !Sync for Closure<'a, A, R> {}
14 impl<'a, A, R> !Send for Closure<'a, A, R> {}
16 impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
17 fn from(f: &'a mut F) -> Self {
18 unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: &mut Env, arg: A) -> R {
19 (*(env as *mut _ as *mut F))(arg)
22 call: call::<A, R, F>,
23 env: unsafe { &mut *(f as *mut _ as *mut Env) },
28 impl<'a, A, R> Closure<'a, A, R> {
29 pub fn call(&mut self, arg: A) -> R {
30 unsafe { (self.call)(self.env, arg) }