From 3edbad34992129b3a1f2f6d448114c97fa5138f1 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 27 Apr 2019 01:41:58 -0400 Subject: [PATCH 1/3] Futures - add BoxFutureLocal type --- futures-core/src/future/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/futures-core/src/future/mod.rs b/futures-core/src/future/mod.rs index 540faf41b2..a1995cb28e 100644 --- a/futures-core/src/future/mod.rs +++ b/futures-core/src/future/mod.rs @@ -14,6 +14,10 @@ pub use self::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj}; /// statically type your result or need to add some indirection. pub type BoxFuture<'a, T> = Pin + Send + 'a>>; +#[cfg(feature = "alloc")] +/// `BoxFuture`, but without the `Send` requirement. +pub type BoxFutureLocal<'a, T> = Pin + 'a>>; + /// A `Future` or `TryFuture` which tracks whether or not the underlying future /// should no longer be polled. /// From 3ecc78da649469daeb3c94e320186a1950b6ecfb Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 27 Apr 2019 01:42:59 -0400 Subject: [PATCH 2/3] FutureExt - add boxed_local() --- futures-util/src/future/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 320ad07929..085934d749 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -10,7 +10,7 @@ use futures_core::task::{Context, Poll}; #[cfg(feature = "alloc")] use alloc::boxed::Box; #[cfg(feature = "alloc")] -use futures_core::future::BoxFuture; +use futures_core::future::{BoxFuture, BoxFutureLocal}; // re-export for `select!` #[doc(hidden)] @@ -499,6 +499,16 @@ pub trait FutureExt: Future { Box::pin(self) } + /// Wrap the future in a Box, pinning it. + /// + /// Similar to `boxed`, but without the `Send` requirement. + #[cfg(feature = "alloc")] + fn boxed_local<'a>(self) -> BoxFutureLocal<'a, Self::Output> + where Self: Sized + 'a + { + Box::pin(self) + } + /// Turns a [`Future`](Future) into a /// [`TryFuture](futures_core::future::TryFuture). fn unit_error(self) -> UnitError From eecc6602f04150f57b6aa54a21cdc2d1dd490018 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 27 Apr 2019 13:02:15 -0400 Subject: [PATCH 3/3] BoxFutureLocal -> LocalBoxFuture --- futures-core/src/future/mod.rs | 2 +- futures-util/src/future/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/futures-core/src/future/mod.rs b/futures-core/src/future/mod.rs index a1995cb28e..110a8289fe 100644 --- a/futures-core/src/future/mod.rs +++ b/futures-core/src/future/mod.rs @@ -16,7 +16,7 @@ pub type BoxFuture<'a, T> = Pin + Send #[cfg(feature = "alloc")] /// `BoxFuture`, but without the `Send` requirement. -pub type BoxFutureLocal<'a, T> = Pin + 'a>>; +pub type LocalBoxFuture<'a, T> = Pin + 'a>>; /// A `Future` or `TryFuture` which tracks whether or not the underlying future /// should no longer be polled. diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 085934d749..cac9d68a9c 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -10,7 +10,7 @@ use futures_core::task::{Context, Poll}; #[cfg(feature = "alloc")] use alloc::boxed::Box; #[cfg(feature = "alloc")] -use futures_core::future::{BoxFuture, BoxFutureLocal}; +use futures_core::future::{BoxFuture, LocalBoxFuture}; // re-export for `select!` #[doc(hidden)] @@ -503,7 +503,7 @@ pub trait FutureExt: Future { /// /// Similar to `boxed`, but without the `Send` requirement. #[cfg(feature = "alloc")] - fn boxed_local<'a>(self) -> BoxFutureLocal<'a, Self::Output> + fn boxed_local<'a>(self) -> LocalBoxFuture<'a, Self::Output> where Self: Sized + 'a { Box::pin(self)