@@ -16,48 +16,45 @@ use crate::marker::Destruct;
16
16
/// assert!(7 == cl(2));
17
17
/// assert!(8 == cl(1));
18
18
/// ```
19
- pub ( crate ) struct ConstFnMutClosure < ' a , CapturedData : ?Sized , Function > {
20
- data : & ' a mut CapturedData ,
21
- func : Function ,
19
+ pub ( crate ) struct ConstFnMutClosure < CapturedData , Function > {
20
+ /// The Data captured by the Closure.
21
+ /// Must be either a (mutable) reference or a tuple of (mutable) references.
22
+ pub data : CapturedData ,
23
+ /// The Function of the Closure, must be: Fn(CapturedData, ClosureArgs) -> ClosureReturn
24
+ pub func : Function ,
22
25
}
23
26
24
- impl < ' a , CapturedData : ?Sized , Function > ConstFnMutClosure < ' a , CapturedData , Function > {
25
- /// Function for creating a new closure.
26
- ///
27
- /// `data` is the a mutable borrow of data that is captured from the environment.
28
- ///
29
- /// `func` is the function of the closure, it gets the data and a tuple of the arguments closure
30
- /// and return the return value of the closure.
31
- pub ( crate ) const fn new < ClosureArguments , ClosureReturnValue > (
32
- data : & ' a mut CapturedData ,
33
- func : Function ,
34
- ) -> Self
35
- where
36
- Function : ~const Fn ( & mut CapturedData , ClosureArguments ) -> ClosureReturnValue ,
37
- {
38
- Self { data, func }
39
- }
40
- }
41
-
42
- impl < ' a , CapturedData : ?Sized , ClosureArguments , Function , ClosureReturnValue > const
43
- FnOnce < ClosureArguments > for ConstFnMutClosure < ' a , CapturedData , Function >
44
- where
45
- Function :
46
- ~const Fn ( & mut CapturedData , ClosureArguments ) -> ClosureReturnValue + ~const Destruct ,
47
- {
48
- type Output = ClosureReturnValue ;
27
+ macro_rules! impl_fn_mut_tuple {
28
+ ( $( $var: ident) * ) => {
29
+ #[ allow( unused_parens) ]
30
+ impl <' a, $( $var, ) * ClosureArguments , Function , ClosureReturnValue > const
31
+ FnOnce <ClosureArguments > for ConstFnMutClosure <( $( & ' a mut $var) ,* ) , Function >
32
+ where
33
+ Function : ~const Fn ( ( $( & mut $var) ,* ) , ClosureArguments ) -> ClosureReturnValue + ~const Destruct ,
34
+ {
35
+ type Output = ClosureReturnValue ;
49
36
50
- extern "rust-call" fn call_once ( mut self , args : ClosureArguments ) -> Self :: Output {
51
- self . call_mut ( args)
52
- }
53
- }
37
+ extern "rust-call" fn call_once( mut self , args: ClosureArguments ) -> Self :: Output {
38
+ self . call_mut( args)
39
+ }
40
+ }
41
+ #[ allow( unused_parens) ]
42
+ impl <' a, $( $var, ) * ClosureArguments , Function , ClosureReturnValue > const
43
+ FnMut <ClosureArguments > for ConstFnMutClosure <( $( & ' a mut $var) ,* ) , Function >
44
+ where
45
+ Function : ~const Fn ( ( $( & mut $var) ,* ) , ClosureArguments ) -> ClosureReturnValue ,
46
+ {
47
+ extern "rust-call" fn call_mut( & mut self , args: ClosureArguments ) -> Self :: Output {
48
+ #[ allow( non_snake_case) ]
49
+ let ( $( $var) ,* ) = & mut self . data;
50
+ ( self . func) ( ( $( $var) ,* ) , args)
51
+ }
52
+ }
54
53
55
- impl < ' a , CapturedData : ?Sized , ClosureArguments , Function , ClosureReturnValue > const
56
- FnMut < ClosureArguments > for ConstFnMutClosure < ' a , CapturedData , Function >
57
- where
58
- Function : ~const Fn ( & mut CapturedData , ClosureArguments ) -> ClosureReturnValue ,
59
- {
60
- extern "rust-call" fn call_mut ( & mut self , args : ClosureArguments ) -> Self :: Output {
61
- ( self . func ) ( self . data , args)
62
- }
63
- }
54
+ } ;
55
+ }
56
+ impl_fn_mut_tuple ! ( A ) ;
57
+ impl_fn_mut_tuple ! ( A B ) ;
58
+ impl_fn_mut_tuple ! ( A B C ) ;
59
+ impl_fn_mut_tuple ! ( A B C D ) ;
60
+ impl_fn_mut_tuple ! ( A B C D E ) ;
0 commit comments