1
+ // #[macro_export]
2
+ // macro_rules! closure {
3
+ // ($name:ident
4
+ // <$($param:ident : $param_type:ty),*>
5
+ // ($($arg:ident : $arg_type:ty),*)
6
+ // |$($larg:ident : $larg_type:ty),*|
7
+ // $body:tt
8
+ // ) => {
9
+ // closure!( $name<$($param:$param_type),*>
10
+ // ($($arg:$arg_type),*)
11
+ // ($($larg:$larg_type)*)
12
+ // $body
13
+ // );
14
+ // };
15
+ // ($name:ident
16
+ // <$($param:ident : $param_type:ty),*>
17
+ // ($($arg:ident : $arg_type:ty),*)
18
+ // || $body:tt) => {
19
+ // closure!($name<$($param:$param_type),*>($($arg:$arg_type),*)()$body);
20
+ // };
21
+ // ($name:ident
22
+ // <$($param:ident : $param_type:ty),*>
23
+ // ($($arg:ident : $arg_type:ty),*)
24
+ // ($($larg:ident : $larg_type:ty),*)
25
+ // $body:tt
26
+ // ) => { paste::item! {
27
+ // pub type [<Closure_ $name>]<$($param),*> =
28
+ // impl Fn($($larg_type),*) + Clone;
29
+ // pub fn $name<$($param:$param_type),*>
30
+ // ($($arg:$arg_type),*) -> [<Closure_ $name>]<$($param),*> {
31
+ // move |$($larg),*| $body
32
+ // }
33
+ // }};
34
+ // }
35
+
1
36
#[ macro_export]
2
37
macro_rules! closure {
3
38
( $name: ident
@@ -24,11 +59,25 @@ macro_rules! closure {
24
59
( $( $larg: ident : $larg_type: ty) ,* )
25
60
$body: tt
26
61
) => { paste:: item! {
62
+ #[ cfg( not( feature = "no_unboxed_callbacks" ) ) ]
27
63
pub type [ <Closure_ $name>] <$( $param) ,* > =
28
64
impl Fn ( $( $larg_type) ,* ) + Clone ;
65
+
66
+ #[ cfg( not( feature = "no_unboxed_callbacks" ) ) ]
29
67
pub fn $name<$( $param: $param_type) ,* >
30
68
( $( $arg: $arg_type) ,* ) -> [ <Closure_ $name>] <$( $param) ,* > {
31
69
move |$( $larg) ,* | $body
32
70
}
71
+
72
+ #[ cfg( feature = "no_unboxed_callbacks" ) ]
73
+ pub type [ <Closure_ $name>] <$( $param) ,* > =
74
+ WithPhantomType <Rc <dyn Fn ( $( $larg_type) ,* ) >, $( $param) ,* >;
75
+
76
+ #[ cfg( feature = "no_unboxed_callbacks" ) ]
77
+ pub fn $name<$( $param: $param_type) ,* >
78
+ ( $( $arg: $arg_type) ,* )
79
+ -> WithPhantomType <Rc <dyn Fn ( $( $larg_type) ,* ) >, $( $param) ,* > {
80
+ WithPhantomType :: new( Rc :: new( move |$( $larg) ,* | $body) )
81
+ }
33
82
} } ;
34
83
}
0 commit comments