1 use crate::marker::Destruct;
3 /// Struct representing a closure with mutably borrowed data.
7 /// #![feature(const_mut_refs)]
8 /// use crate::const_closure::ConstFnMutClosure;
9 /// const fn imp(state: &mut i32, (arg,): (i32,)) -> i32 {
14 /// let mut cl = ConstFnMutClosure::new(&mut i, imp);
16 /// assert!(7 == cl(2));
17 /// assert!(8 == cl(1));
19 pub(crate) struct ConstFnMutClosure<'a, CapturedData: ?Sized, Function> {
20 data: &'a mut CapturedData,
24 impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Function> {
25 /// Function for creating a new closure.
27 /// `data` is the a mutable borrow of data that is captured from the environment.
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,
36 Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
42 impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
43 FnOnce<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
46 ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct,
48 type Output = ClosureReturnValue;
50 extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
55 impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
56 FnMut<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
58 Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
60 extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
61 (self.func)(self.data, args)