Skip to content

Commit e19e43e

Browse files
committed
Deprecate and rename FutureExt::{left, right}
1 parent b8369e2 commit e19e43e

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

futures-util/src/future/mod.rs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,49 @@ pub trait FutureExt: Future {
509509
/// assert_eq!(x, block_on(future).unwrap());
510510
/// # }
511511
/// ```
512+
#[deprecated(note = "use `left_future` instead")]
512513
fn left<B>(self) -> Either<Self, B>
513514
where B: Future<Item = Self::Item, Error = Self::Error>,
514515
Self: Sized
515516
{
516517
Either::Left(self)
517518
}
518519

520+
/// Wrap this future in an `Either` future, making it the left-hand variant
521+
/// of that `Either`.
522+
///
523+
/// This can be used in combination with the `right_future` method to write `if`
524+
/// statements that evaluate to different futures in different branches.
525+
///
526+
/// # Examples
527+
///
528+
/// ```
529+
/// # extern crate futures;
530+
/// use futures::executor::block_on;
531+
/// use futures::future::*;
532+
///
533+
/// # fn main() {
534+
/// let x = 6;
535+
/// let future = if x < 10 {
536+
/// ok::<_, bool>(x).left_future()
537+
/// } else {
538+
/// empty().right_future()
539+
/// };
540+
///
541+
/// assert_eq!(x, block_on(future).unwrap());
542+
/// # }
543+
/// ```
544+
fn left_future<B>(self) -> Either<Self, B>
545+
where B: Future<Item = Self::Item, Error = Self::Error>,
546+
Self: Sized
547+
{
548+
Either::Left(self)
549+
}
550+
519551
/// Wrap this future in an `Either` future, making it the right-hand variant
520552
/// of that `Either`.
521553
///
522-
/// This can be used in combination with the `left` method to write `if`
554+
/// This can be used in combination with the `left_future` method to write `if`
523555
/// statements that evaluate to different futures in different branches.
524556
///
525557
/// # Examples
@@ -540,13 +572,45 @@ pub trait FutureExt: Future {
540572
/// assert_eq!(x, block_on(future).unwrap());
541573
/// # }
542574
/// ```
575+
#[deprecated(note = "use `right_future` instead")]
543576
fn right<A>(self) -> Either<A, Self>
544577
where A: Future<Item = Self::Item, Error = Self::Error>,
545578
Self: Sized,
546579
{
547580
Either::Right(self)
548581
}
549582

583+
/// Wrap this future in an `Either` future, making it the right-hand variant
584+
/// of that `Either`.
585+
///
586+
/// This can be used in combination with the `left_future` method to write `if`
587+
/// statements that evaluate to different futures in different branches.
588+
///
589+
/// # Examples
590+
///
591+
/// ```
592+
/// # extern crate futures;
593+
/// use futures::executor::block_on;
594+
/// use futures::future::*;
595+
///
596+
/// # fn main() {
597+
/// let x = 6;
598+
/// let future = if x < 10 {
599+
/// ok::<_, bool>(x).left_future()
600+
/// } else {
601+
/// empty().right_future()
602+
/// };
603+
///
604+
/// assert_eq!(x, block_on(future).unwrap());
605+
/// # }
606+
/// ```
607+
fn right_future<A>(self) -> Either<A, Self>
608+
where A: Future<Item = Self::Item, Error = Self::Error>,
609+
Self: Sized,
610+
{
611+
Either::Right(self)
612+
}
613+
550614
/// Convert this future into a single element stream.
551615
///
552616
/// The returned stream contains single success if this future resolves to

futures-util/src/stream/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,12 @@ pub trait StreamExt: Stream {
962962
recover::new(self, f)
963963
}
964964

965-
966965
/// Wrap this stream in an `Either` stream, making it the left-hand variant
967966
/// of that `Either`.
968967
///
969968
/// This can be used in combination with the `right` method to write `if`
970969
/// statements that evaluate to different streams in different branches.
970+
#[deprecated(note = "use `left_stream` instead")]
971971
fn left<B>(self) -> Either<Self, B>
972972
where B: Stream<Item = Self::Item, Error = Self::Error>,
973973
Self: Sized
@@ -980,10 +980,35 @@ pub trait StreamExt: Stream {
980980
///
981981
/// This can be used in combination with the `left` method to write `if`
982982
/// statements that evaluate to different streams in different branches.
983+
#[deprecated(note = "use `right_stream` instead")]
983984
fn right<B>(self) -> Either<B, Self>
984985
where B: Stream<Item = Self::Item, Error = Self::Error>,
985986
Self: Sized
986987
{
987988
Either::Right(self)
988989
}
990+
991+
/// Wrap this stream in an `Either` stream, making it the left-hand variant
992+
/// of that `Either`.
993+
///
994+
/// This can be used in combination with the `right_stream` method to write `if`
995+
/// statements that evaluate to different streams in different branches.
996+
fn left_stream<B>(self) -> Either<Self, B>
997+
where B: Stream<Item = Self::Item, Error = Self::Error>,
998+
Self: Sized
999+
{
1000+
Either::Left(self)
1001+
}
1002+
1003+
/// Wrap this stream in an `Either` stream, making it the right-hand variant
1004+
/// of that `Either`.
1005+
///
1006+
/// This can be used in combination with the `left_stream` method to write `if`
1007+
/// statements that evaluate to different streams in different branches.
1008+
fn right_stream<B>(self) -> Either<B, Self>
1009+
where B: Stream<Item = Self::Item, Error = Self::Error>,
1010+
Self: Sized
1011+
{
1012+
Either::Right(self)
1013+
}
9891014
}

0 commit comments

Comments
 (0)