Skip to content

Commit b54f9a9

Browse files
ibraheemdevtaiki-e
authored andcommitted
add either example
1 parent 18b977d commit b54f9a9

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

futures-util/src/future/either.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@ use futures_core::stream::{FusedStream, Stream};
55
#[cfg(feature = "sink")]
66
use futures_sink::Sink;
77

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+
/// ```
1027
#[derive(Debug, Clone)]
1128
pub enum Either<A, B> {
1229
/// First branch of the type

futures-util/src/sink/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub trait SinkExt<Item>: Sink<Item> {
243243
/// This future will drive the stream to keep producing items until it is
244244
/// exhausted, sending each item to the sink. It will complete once both the
245245
/// 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
247247
/// an error, that error will be returned by this future without flushing the sink.
248248
///
249249
/// Doing `sink.send_all(stream)` is roughly equivalent to

0 commit comments

Comments
 (0)