From 5ed178741358db3258d804f332d82e497b7eb11a Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Tue, 30 Aug 2022 11:21:07 +0200 Subject: [PATCH] Implement `Ready::into_inner()` --- library/core/src/future/ready.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 @@ fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { } } +impl Ready { + /// 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