Skip to content

Commit e7c0b77

Browse files
committed
add either example
1 parent f94dd92 commit e7c0b77

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

futures-util/src/future/either.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ 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, Future};
14+
/// let cond = true;
15+
///
16+
/// let fut = if cond {
17+
/// Either::Left(async move { 12 })
18+
/// } else {
19+
/// Either::Right(async move { 44 })
20+
/// };
21+
///
22+
/// assert_eq!(fut.await, 12);
23+
/// ```
1024
#[derive(Debug, Clone)]
1125
pub enum Either<A, B> {
1226
/// First branch of the type

0 commit comments

Comments
 (0)