Skip to content

Commit 4db2b74

Browse files
authored
Rollup merge of #116241 - dtolnay:exclusivefwd, r=Amanieu
Add Exclusive forwarding impls (FnOnce, FnMut, Generator) This is adapted from #104057.
2 parents 60ba6b4 + a95f20c commit 4db2b74

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

library/core/src/sync/exclusive.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use core::fmt;
44
use core::future::Future;
5+
use core::marker::Tuple;
6+
use core::ops::{Generator, GeneratorState};
57
use core::pin::Pin;
68
use core::task::{Context, Poll};
79

@@ -168,10 +170,52 @@ impl<T> From<T> for Exclusive<T> {
168170
}
169171

170172
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
171-
impl<T: Future + ?Sized> Future for Exclusive<T> {
173+
impl<F, Args> FnOnce<Args> for Exclusive<F>
174+
where
175+
F: FnOnce<Args>,
176+
Args: Tuple,
177+
{
178+
type Output = F::Output;
179+
180+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output {
181+
self.into_inner().call_once(args)
182+
}
183+
}
184+
185+
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
186+
impl<F, Args> FnMut<Args> for Exclusive<F>
187+
where
188+
F: FnMut<Args>,
189+
Args: Tuple,
190+
{
191+
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output {
192+
self.get_mut().call_mut(args)
193+
}
194+
}
195+
196+
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
197+
impl<T> Future for Exclusive<T>
198+
where
199+
T: Future + ?Sized,
200+
{
172201
type Output = T::Output;
202+
173203
#[inline]
174204
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
175205
self.get_pin_mut().poll(cx)
176206
}
177207
}
208+
209+
#[unstable(feature = "generator_trait", issue = "43122")] // also #98407
210+
impl<R, G> Generator<R> for Exclusive<G>
211+
where
212+
G: Generator<R> + ?Sized,
213+
{
214+
type Yield = G::Yield;
215+
type Return = G::Return;
216+
217+
#[inline]
218+
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
219+
G::resume(self.get_pin_mut(), arg)
220+
}
221+
}

0 commit comments

Comments
 (0)