From a196641dc7518cf9eb028efbf73c3d0ba4f78900 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 16 Sep 2020 12:43:54 +0200 Subject: [PATCH] Rename core::future::poll_fn to core::future::from_fn --- .../src/future/{poll_fn.rs => from_fn.rs} | 37 +++++++++---------- library/core/src/future/mod.rs | 6 +-- library/std/src/future.rs | 4 ++ library/std/src/lib.rs | 1 + 4 files changed, 26 insertions(+), 22 deletions(-) rename library/core/src/future/{poll_fn.rs => from_fn.rs} (51%) diff --git a/library/core/src/future/poll_fn.rs b/library/core/src/future/from_fn.rs similarity index 51% rename from library/core/src/future/poll_fn.rs rename to library/core/src/future/from_fn.rs index f302cda09e721..a2b3b3d22bfe7 100644 --- a/library/core/src/future/poll_fn.rs +++ b/library/core/src/future/from_fn.rs @@ -10,49 +10,48 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// #![feature(future_poll_fn)] +/// #![feature(future_from_fn)] /// # async fn run() { -/// use core::future::poll_fn; +/// use core::future; /// use core::task::{Context, Poll}; /// -/// fn read_line(_cx: &mut Context<'_>) -> Poll { +/// let fut = future::from_fn(|_cx: &mut Context<'_>| -> Poll { /// Poll::Ready("Hello, World!".into()) -/// } +/// }); /// -/// let read_future = poll_fn(read_line); -/// assert_eq!(read_future.await, "Hello, World!".to_owned()); +/// assert_eq!(fut.await, "Hello, World!".to_owned()); /// # }; /// ``` -#[unstable(feature = "future_poll_fn", issue = "72302")] -pub fn poll_fn(f: F) -> PollFn +#[unstable(feature = "future_from_fn", issue = "72302")] +pub fn from_fn(f: F) -> FromFn where F: FnMut(&mut Context<'_>) -> Poll, { - PollFn { f } + FromFn { f } } /// A Future that wraps a function returning `Poll`. /// -/// This `struct` is created by [`poll_fn()`]. See its +/// This `struct` is created by [`from_fn()`]. See its /// documentation for more. #[must_use = "futures do nothing unless you `.await` or poll them"] -#[unstable(feature = "future_poll_fn", issue = "72302")] -pub struct PollFn { +#[unstable(feature = "future_from_fn", issue = "72302")] +pub struct FromFn { f: F, } -#[unstable(feature = "future_poll_fn", issue = "72302")] -impl Unpin for PollFn {} +#[unstable(feature = "future_from_fn", issue = "72302")] +impl Unpin for FromFn {} -#[unstable(feature = "future_poll_fn", issue = "72302")] -impl fmt::Debug for PollFn { +#[unstable(feature = "future_from_fn", issue = "72302")] +impl fmt::Debug for FromFn { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("PollFn").finish() + f.debug_struct("FromFn").finish() } } -#[unstable(feature = "future_poll_fn", issue = "72302")] -impl Future for PollFn +#[unstable(feature = "future_from_fn", issue = "72302")] +impl Future for FromFn where F: FnMut(&mut Context<'_>) -> Poll, { diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs index fa5655ca35f41..0c318104c0a42 100644 --- a/library/core/src/future/mod.rs +++ b/library/core/src/future/mod.rs @@ -9,10 +9,10 @@ use crate::{ task::{Context, Poll}, }; +mod from_fn; mod future; mod into_future; mod pending; -mod poll_fn; mod ready; #[stable(feature = "futures_api", since = "1.36.0")] @@ -26,8 +26,8 @@ pub use pending::{pending, Pending}; #[stable(feature = "future_readiness_fns", since = "1.48.0")] pub use ready::{ready, Ready}; -#[unstable(feature = "future_poll_fn", issue = "72302")] -pub use poll_fn::{poll_fn, PollFn}; +#[unstable(feature = "future_from_fn", issue = "72302")] +pub use from_fn::{from_fn, FromFn}; /// This type is needed because: /// diff --git a/library/std/src/future.rs b/library/std/src/future.rs index 9d9c36e9afb0f..d1076b060a0d7 100644 --- a/library/std/src/future.rs +++ b/library/std/src/future.rs @@ -12,6 +12,10 @@ pub use core::future::{from_generator, get_context, ResumeTy}; #[stable(feature = "future_readiness_fns", since = "1.48.0")] pub use core::future::{pending, ready, Pending, Ready}; +#[doc(inline)] +#[unstable(feature = "future_from_fn", issue = "72302")] +pub use core::future::{from_fn, FromFn}; + #[doc(inline)] #[unstable(feature = "into_future", issue = "67644")] pub use core::future::IntoFuture; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 309657e70424b..abf0afb7f9a57 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -258,6 +258,7 @@ #![feature(external_doc)] #![feature(fn_traits)] #![feature(format_args_nl)] +#![feature(future_from_fn)] #![feature(gen_future)] #![feature(generator_trait)] #![feature(global_asm)]