mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-10-02 14:44:32 +00:00
Merge pull request #3650 from avsaase/either-is
Add is_x() methods for all EitherN enum variants
This commit is contained in:
commit
c77560430e
@ -14,6 +14,18 @@ pub enum Either<A, B> {
|
|||||||
Second(B),
|
Second(B),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B> Either<A, B> {
|
||||||
|
/// Did the first future complete first?
|
||||||
|
pub fn is_first(&self) -> bool {
|
||||||
|
matches!(self, Either::First(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the second future complete first?
|
||||||
|
pub fn is_second(&self) -> bool {
|
||||||
|
matches!(self, Either::Second(_))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Wait for one of two futures to complete.
|
/// Wait for one of two futures to complete.
|
||||||
///
|
///
|
||||||
/// This function returns a new future which polls all the futures.
|
/// This function returns a new future which polls all the futures.
|
||||||
@ -73,6 +85,23 @@ pub enum Either3<A, B, C> {
|
|||||||
Third(C),
|
Third(C),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B, C> Either3<A, B, C> {
|
||||||
|
/// Did the first future complete first?
|
||||||
|
pub fn is_first(&self) -> bool {
|
||||||
|
matches!(self, Either3::First(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the second future complete first?
|
||||||
|
pub fn is_second(&self) -> bool {
|
||||||
|
matches!(self, Either3::Second(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the third future complete first?
|
||||||
|
pub fn is_third(&self) -> bool {
|
||||||
|
matches!(self, Either3::Third(_))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Same as [`select`], but with more futures.
|
/// Same as [`select`], but with more futures.
|
||||||
pub fn select3<A, B, C>(a: A, b: B, c: C) -> Select3<A, B, C>
|
pub fn select3<A, B, C>(a: A, b: B, c: C) -> Select3<A, B, C>
|
||||||
where
|
where
|
||||||
@ -134,6 +163,28 @@ pub enum Either4<A, B, C, D> {
|
|||||||
Fourth(D),
|
Fourth(D),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B, C, D> Either4<A, B, C, D> {
|
||||||
|
/// Did the first future complete first?
|
||||||
|
pub fn is_first(&self) -> bool {
|
||||||
|
matches!(self, Either4::First(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the second future complete first?
|
||||||
|
pub fn is_second(&self) -> bool {
|
||||||
|
matches!(self, Either4::Second(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the third future complete first?
|
||||||
|
pub fn is_third(&self) -> bool {
|
||||||
|
matches!(self, Either4::Third(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the fourth future complete first?
|
||||||
|
pub fn is_fourth(&self) -> bool {
|
||||||
|
matches!(self, Either4::Fourth(_))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Same as [`select`], but with more futures.
|
/// Same as [`select`], but with more futures.
|
||||||
pub fn select4<A, B, C, D>(a: A, b: B, c: C, d: D) -> Select4<A, B, C, D>
|
pub fn select4<A, B, C, D>(a: A, b: B, c: C, d: D) -> Select4<A, B, C, D>
|
||||||
where
|
where
|
||||||
@ -204,6 +255,33 @@ pub enum Either5<A, B, C, D, E> {
|
|||||||
Fifth(E),
|
Fifth(E),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B, C, D, E> Either5<A, B, C, D, E> {
|
||||||
|
/// Did the first future complete first?
|
||||||
|
pub fn is_first(&self) -> bool {
|
||||||
|
matches!(self, Either5::First(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the second future complete first?
|
||||||
|
pub fn is_second(&self) -> bool {
|
||||||
|
matches!(self, Either5::Second(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the third future complete first?
|
||||||
|
pub fn is_third(&self) -> bool {
|
||||||
|
matches!(self, Either5::Third(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the fourth future complete first?
|
||||||
|
pub fn is_fourth(&self) -> bool {
|
||||||
|
matches!(self, Either5::Fourth(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the fifth future complete first?
|
||||||
|
pub fn is_fifth(&self) -> bool {
|
||||||
|
matches!(self, Either5::Fifth(_))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Same as [`select`], but with more futures.
|
/// Same as [`select`], but with more futures.
|
||||||
pub fn select5<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E) -> Select5<A, B, C, D, E>
|
pub fn select5<A, B, C, D, E>(a: A, b: B, c: C, d: D, e: E) -> Select5<A, B, C, D, E>
|
||||||
where
|
where
|
||||||
@ -283,6 +361,38 @@ pub enum Either6<A, B, C, D, E, F> {
|
|||||||
Sixth(F),
|
Sixth(F),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B, C, D, E, F> Either6<A, B, C, D, E, F> {
|
||||||
|
/// Did the first future complete first?
|
||||||
|
pub fn is_first(&self) -> bool {
|
||||||
|
matches!(self, Either6::First(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the second future complete first?
|
||||||
|
pub fn is_second(&self) -> bool {
|
||||||
|
matches!(self, Either6::Second(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the third future complete first?
|
||||||
|
pub fn is_third(&self) -> bool {
|
||||||
|
matches!(self, Either6::Third(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the fourth future complete first?
|
||||||
|
pub fn is_fourth(&self) -> bool {
|
||||||
|
matches!(self, Either6::Fourth(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the fifth future complete first?
|
||||||
|
pub fn is_fifth(&self) -> bool {
|
||||||
|
matches!(self, Either6::Fifth(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Did the sixth future complete first?
|
||||||
|
pub fn is_sixth(&self) -> bool {
|
||||||
|
matches!(self, Either6::Sixth(_))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Same as [`select`], but with more futures.
|
/// Same as [`select`], but with more futures.
|
||||||
pub fn select6<A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F) -> Select6<A, B, C, D, E, F>
|
pub fn select6<A, B, C, D, E, F>(a: A, b: B, c: C, d: D, e: E, f: F) -> Select6<A, B, C, D, E, F>
|
||||||
where
|
where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user