|
1 | 1 | //! Closure type (equivalent to `&mut dyn FnMut(A) -> R`) that's `repr(C)`.
|
2 | 2 |
|
| 3 | +use std::marker::PhantomData; |
| 4 | + |
3 | 5 | #[repr(C)]
|
4 | 6 | pub struct Closure<'a, A, R> {
|
5 |
| - call: unsafe extern "C" fn(&mut Env, A) -> R, |
6 |
| - env: &'a mut Env, |
| 7 | + call: unsafe extern "C" fn(*mut Env, A) -> R, |
| 8 | + env: *mut Env, |
| 9 | + _marker: PhantomData<&'a mut ()>, |
7 | 10 | }
|
8 | 11 |
|
9 |
| -extern "C" { |
10 |
| - type Env; |
11 |
| -} |
| 12 | +struct Env; |
12 | 13 |
|
13 | 14 | impl<'a, A, R> !Sync for Closure<'a, A, R> {}
|
14 | 15 | impl<'a, A, R> !Send for Closure<'a, A, R> {}
|
15 | 16 |
|
16 | 17 | impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
|
17 | 18 | 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 | + unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: *mut Env, arg: A) -> R { |
19 | 20 | (*(env as *mut _ as *mut F))(arg)
|
20 | 21 | }
|
21 |
| - Closure { call: call::<A, R, F>, env: unsafe { &mut *(f as *mut _ as *mut Env) } } |
| 22 | + Closure { call: call::<A, R, F>, env: f as *mut _ as *mut Env, _marker: PhantomData } |
22 | 23 | }
|
23 | 24 | }
|
24 | 25 |
|
|
0 commit comments