Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions futures-core/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<alloc::boxed::Box<dyn Future<Output = T> + Send + 'a>>;

#[cfg(feature = "alloc")]
/// `BoxFuture`, but without the `Send` requirement.
pub type LocalBoxFuture<'a, T> = Pin<alloc::boxed::Box<dyn Future<Output = T> + 'a>>;

/// A `Future` or `TryFuture` which tracks whether or not the underlying future
/// should no longer be polled.
///
Expand Down
12 changes: 11 additions & 1 deletion futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, LocalBoxFuture};

// re-export for `select!`
#[doc(hidden)]
Expand Down Expand Up @@ -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) -> LocalBoxFuture<'a, Self::Output>
where Self: Sized + 'a
{
Box::pin(self)
}

/// Turns a [`Future<Output = T>`](Future) into a
/// [`TryFuture<Ok = T, Error = ()`>](futures_core::future::TryFuture).
fn unit_error(self) -> UnitError<Self>
Expand Down