Skip to content

Commit

Permalink
Document how BoxFutures / BoxStreams are often made (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Oct 4, 2024
1 parent 2d4f685 commit bbfc1ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions futures-core/src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ pub use core::future::Future;

/// An owned dynamically typed [`Future`] for use in cases where you can't
/// statically type your result or need to add some indirection.
///
/// This type is often created by the [`boxed`] method on [`FutureExt`]. See its documentation for more.
///
/// [`boxed`]: https://docs.rs/futures/latest/futures/future/trait.FutureExt.html#method.boxed
/// [`FutureExt`]: https://docs.rs/futures/latest/futures/future/trait.FutureExt.html
#[cfg(feature = "alloc")]
pub type BoxFuture<'a, T> = Pin<alloc::boxed::Box<dyn Future<Output = T> + Send + 'a>>;

/// `BoxFuture`, but without the `Send` requirement.
///
/// This type is often created by the [`boxed_local`] method on [`FutureExt`]. See its documentation for more.
///
/// [`boxed_local`]: https://docs.rs/futures/latest/futures/future/trait.FutureExt.html#method.boxed_local
/// [`FutureExt`]: https://docs.rs/futures/latest/futures/future/trait.FutureExt.html
#[cfg(feature = "alloc")]
pub type LocalBoxFuture<'a, T> = Pin<alloc::boxed::Box<dyn Future<Output = T> + 'a>>;

Expand Down
10 changes: 10 additions & 0 deletions futures-core/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ use core::task::{Context, Poll};

/// An owned dynamically typed [`Stream`] for use in cases where you can't
/// statically type your result or need to add some indirection.
///
/// This type is often created by the [`boxed`] method on [`StreamExt`]. See its documentation for more.
///
/// [`boxed`]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.boxed
/// [`StreamExt`]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html
#[cfg(feature = "alloc")]
pub type BoxStream<'a, T> = Pin<alloc::boxed::Box<dyn Stream<Item = T> + Send + 'a>>;

/// `BoxStream`, but without the `Send` requirement.
///
/// This type is often created by the [`boxed_local`] method on [`StreamExt`]. See its documentation for more.
///
/// [`boxed_local`]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.boxed_local
/// [`StreamExt`]: https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html
#[cfg(feature = "alloc")]
pub type LocalBoxStream<'a, T> = Pin<alloc::boxed::Box<dyn Stream<Item = T> + 'a>>;

Expand Down

0 comments on commit bbfc1ed

Please sign in to comment.