@@ -23,36 +23,53 @@ pub(crate) struct ConstFnMutClosure<CapturedData, Function> {
2323 /// The Function of the Closure, must be: Fn(CapturedData, ClosureArgs) -> ClosureReturn
2424 pub func : Function ,
2525}
26+ impl < ' a , CapturedData : ?Sized , Function > ConstFnMutClosure < & ' a mut CapturedData , Function > {
27+ /// Function for creating a new closure.
28+ ///
29+ /// `data` is the a mutable borrow of data that is captured from the environment.
30+ /// If you want Data to be a tuple of mutable Borrows, the struct must be constructed manually.
31+ ///
32+ /// `func` is the function of the closure, it gets the data and a tuple of the arguments closure
33+ /// and return the return value of the closure.
34+ pub ( crate ) const fn new < ClosureArguments , ClosureReturnValue > (
35+ data : & ' a mut CapturedData ,
36+ func : Function ,
37+ ) -> Self
38+ where
39+ Function : ~const Fn ( & mut CapturedData , ClosureArguments ) -> ClosureReturnValue ,
40+ {
41+ Self { data, func }
42+ }
43+ }
2644
2745macro_rules! impl_fn_mut_tuple {
2846 ( $( $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 ;
47+ #[ allow( unused_parens) ]
48+ impl <' a, $( $var, ) * ClosureArguments , Function , ClosureReturnValue > const
49+ FnOnce <ClosureArguments > for ConstFnMutClosure <( $( & ' a mut $var) ,* ) , Function >
50+ where
51+ Function : ~const Fn ( ( $( & mut $var) ,* ) , ClosureArguments ) -> ClosureReturnValue + ~const Destruct ,
52+ {
53+ type Output = ClosureReturnValue ;
3654
37- extern "rust-call" fn call_once( mut self , args: ClosureArguments ) -> Self :: Output {
38- self . call_mut( args)
55+ extern "rust-call" fn call_once( mut self , args: ClosureArguments ) -> Self :: Output {
56+ self . call_mut( args)
57+ }
3958 }
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 )
59+ # [ allow ( unused_parens ) ]
60+ impl < ' a , $ ( $var , ) * ClosureArguments , Function , ClosureReturnValue > const
61+ FnMut < ClosureArguments > for ConstFnMutClosure < ( $ ( & ' a mut $ var) , * ) , Function >
62+ where
63+ Function : ~ const Fn ( ( $ ( & mut $var ) , * ) , ClosureArguments ) -> ClosureReturnValue ,
64+ {
65+ extern "rust-call" fn call_mut ( & mut self , args : ClosureArguments ) -> Self :: Output {
66+ # [ allow ( non_snake_case ) ]
67+ let ( $ ( $var ) , * ) = & mut self . data ;
68+ ( self . func ) ( ( $( $var) ,* ) , args )
69+ }
5170 }
52- }
53-
5471 } ;
55- }
72+ }
5673impl_fn_mut_tuple ! ( A ) ;
5774impl_fn_mut_tuple ! ( A B ) ;
5875impl_fn_mut_tuple ! ( A B C ) ;
0 commit comments