remove Closure generics
This commit is contained in:
parent
1a240d604c
commit
749d62b262
3 changed files with 13 additions and 11 deletions
|
|
@ -129,7 +129,7 @@ struct Bridge<'a> {
|
|||
cached_buffer: Buffer,
|
||||
|
||||
/// Server-side function that the client uses to make requests.
|
||||
dispatch: closure::Closure<'a, Buffer, Buffer>,
|
||||
dispatch: closure::Closure<'a>,
|
||||
|
||||
/// Provided globals for this macro expansion.
|
||||
globals: ExpnGlobals<Span>,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
//! Closure type (equivalent to `&mut dyn FnMut(A) -> R`) that's `repr(C)`.
|
||||
//! Closure type (equivalent to `&mut dyn FnMut(Buffer) -> Buffer`) that's `repr(C)`.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use super::Buffer;
|
||||
|
||||
#[repr(C)]
|
||||
pub(super) struct Closure<'a, A, R> {
|
||||
call: unsafe extern "C" fn(*mut Env, A) -> R,
|
||||
pub(super) struct Closure<'a> {
|
||||
call: extern "C" fn(*mut Env, Buffer) -> Buffer,
|
||||
env: *mut Env,
|
||||
// Prevent Send and Sync impls.
|
||||
//
|
||||
|
|
@ -14,17 +16,17 @@ pub(super) struct Closure<'a, A, R> {
|
|||
|
||||
struct Env;
|
||||
|
||||
impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
|
||||
impl<'a, F: FnMut(Buffer) -> Buffer> From<&'a mut F> for Closure<'a> {
|
||||
fn from(f: &'a mut F) -> Self {
|
||||
unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: *mut Env, arg: A) -> R {
|
||||
extern "C" fn call<F: FnMut(Buffer) -> Buffer>(env: *mut Env, arg: Buffer) -> Buffer {
|
||||
unsafe { (*(env as *mut _ as *mut F))(arg) }
|
||||
}
|
||||
Closure { call: call::<A, R, F>, env: f as *mut _ as *mut Env, _marker: PhantomData }
|
||||
Closure { call: call::<F>, env: f as *mut _ as *mut Env, _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A, R> Closure<'a, A, R> {
|
||||
pub(super) fn call(&mut self, arg: A) -> R {
|
||||
unsafe { (self.call)(self.env, arg) }
|
||||
impl<'a> Closure<'a> {
|
||||
pub(super) fn call(&mut self, arg: Buffer) -> Buffer {
|
||||
(self.call)(self.env, arg)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ pub struct BridgeConfig<'a> {
|
|||
input: Buffer,
|
||||
|
||||
/// Server-side function that the client uses to make requests.
|
||||
dispatch: closure::Closure<'a, Buffer, Buffer>,
|
||||
dispatch: closure::Closure<'a>,
|
||||
|
||||
/// If 'true', always invoke the default panic hook
|
||||
force_show_panics: bool,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue