File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,25 @@ use futures_core::stream::{FusedStream, Stream};
5
5
#[ cfg( feature = "sink" ) ]
6
6
use futures_sink:: Sink ;
7
7
8
- /// Combines two different futures, streams, or sinks having the same associated types into a single
9
- /// type.
8
+ /// Combines two different futures, streams, or sinks having the same associated types into a single type.
9
+ ///
10
+ /// This is useful when conditionally choosing between two distinct future types:
11
+ ///
12
+ /// ```rust
13
+ /// use futures::future::Either;
14
+ ///
15
+ /// # futures::executor::block_on(async {
16
+ /// let cond = true;
17
+ ///
18
+ /// let fut = if cond {
19
+ /// Either::Left(async move { 12 })
20
+ /// } else {
21
+ /// Either::Right(async move { 44 })
22
+ /// };
23
+ ///
24
+ /// assert_eq!(fut.await, 12);
25
+ /// # })
26
+ /// ```
10
27
#[ derive( Debug , Clone ) ]
11
28
pub enum Either < A , B > {
12
29
/// First branch of the type
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ pub trait SinkExt<Item>: Sink<Item> {
243
243
/// This future will drive the stream to keep producing items until it is
244
244
/// exhausted, sending each item to the sink. It will complete once both the
245
245
/// stream is exhausted, the sink has received all items, and the sink has
246
- /// been flushed. Note that the sink is **not** closed. If the stream produces
246
+ /// been flushed. Note that the sink is **not** closed. If the stream produces
247
247
/// an error, that error will be returned by this future without flushing the sink.
248
248
///
249
249
/// Doing `sink.send_all(stream)` is roughly equivalent to
You can’t perform that action at this time.
0 commit comments