diff options
| author | dAxpeDDa <daxpedda@gmail.com> | 2022-08-30 11:21:07 +0200 |
|---|---|---|
| committer | dAxpeDDa <daxpedda@gmail.com> | 2022-08-30 13:39:30 +0200 |
| commit | 5ed178741358db3258d804f332d82e497b7eb11a (patch) | |
| tree | 2e200afb3242264a9b1e6f4be80cd8b82ceedaff | |
| parent | a0d07093f80a0206f42d3dbada66212eda52b694 (diff) | |
| download | rust-5ed178741358db3258d804f332d82e497b7eb11a.tar.gz rust-5ed178741358db3258d804f332d82e497b7eb11a.zip | |
Implement `Ready::into_inner()`
| -rw-r--r-- | library/core/src/future/ready.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/library/core/src/future/ready.rs b/library/core/src/future/ready.rs index 48f20f90a32..a07b63fb62b 100644 --- a/library/core/src/future/ready.rs +++ b/library/core/src/future/ready.rs @@ -24,6 +24,30 @@ impl<T> Future for Ready<T> { } } +impl<T> Ready<T> { + /// Consumes the `Ready`, returning the wrapped value. + /// + /// # Panics + /// + /// Will panic if this [`Ready`] was already polled to completion. + /// + /// # Examples + /// + /// ``` + /// #![feature(ready_into_inner)] + /// use std::future; + /// + /// let a = future::ready(1); + /// assert_eq!(a.into_inner(), 1); + /// ``` + #[unstable(feature = "ready_into_inner", issue = "101196")] + #[must_use] + #[inline] + pub fn into_inner(self) -> T { + self.0.expect("Called `into_inner()` on `Ready` after completion") + } +} + /// Creates a future that is immediately ready with a value. /// /// Futures created through this function are functionally similar to those |
