Skip to content

Commit f3fb74d

Browse files
alambtaiki-e
authored andcommitted
Document how BoxFutures / BoxStreams are often made (#2887)
1 parent f00e7af commit f3fb74d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

futures-core/src/future.rs

+10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ pub use core::future::Future;
99

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

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

futures-core/src/stream.rs

+10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ use core::task::{Context, Poll};
66

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

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

0 commit comments

Comments
 (0)