|
2 | 2 |
|
3 | 3 | use core::fmt;
|
4 | 4 | use core::future::Future;
|
| 5 | +use core::marker::Tuple; |
| 6 | +use core::ops::{Generator, GeneratorState}; |
5 | 7 | use core::pin::Pin;
|
6 | 8 | use core::task::{Context, Poll};
|
7 | 9 |
|
@@ -168,10 +170,52 @@ impl<T> From<T> for Exclusive<T> {
|
168 | 170 | }
|
169 | 171 |
|
170 | 172 | #[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 | +{ |
172 | 201 | type Output = T::Output;
|
| 202 | + |
173 | 203 | #[inline]
|
174 | 204 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
175 | 205 | self.get_pin_mut().poll(cx)
|
176 | 206 | }
|
177 | 207 | }
|
| 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