From 1d875fab2dc9d765ebf9f4b37112581301f2ed7e Mon Sep 17 00:00:00 2001 From: alexmoon Date: Tue, 12 Apr 2022 18:55:57 -0400 Subject: [PATCH] Use embassy::util::select3 --- embassy-usb/src/lib.rs | 1 + embassy-usb/src/util.rs | 52 ----------------------------------------- 2 files changed, 1 insertion(+), 52 deletions(-) diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 11561430b..102ccbb3a 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -15,6 +15,7 @@ mod util; use driver::Unsupported; use embassy::blocking_mutex::raw::{NoopRawMutex, RawMutex}; use embassy::channel::Channel; +use embassy::util::{select3, Either3}; use heapless::Vec; use self::control::*; diff --git a/embassy-usb/src/util.rs b/embassy-usb/src/util.rs index 4fc55461f..3f20262c6 100644 --- a/embassy-usb/src/util.rs +++ b/embassy-usb/src/util.rs @@ -6,58 +6,6 @@ use core::task::{Context, Poll}; use embassy::blocking_mutex::raw::RawMutex; use embassy::channel::Channel; -#[derive(Debug, Clone)] -pub enum Either3 { - First(A), - Second(B), - Third(C), -} - -/// Same as [`select`], but with more futures. -pub fn select3(a: A, b: B, c: C) -> Select3 -where - A: Future, - B: Future, - C: Future, -{ - Select3 { a, b, c } -} - -/// Future for the [`select3`] function. -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Select3 { - a: A, - b: B, - c: C, -} - -impl Future for Select3 -where - A: Future, - B: Future, - C: Future, -{ - type Output = Either3; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = unsafe { self.get_unchecked_mut() }; - let a = unsafe { Pin::new_unchecked(&mut this.a) }; - let b = unsafe { Pin::new_unchecked(&mut this.b) }; - let c = unsafe { Pin::new_unchecked(&mut this.c) }; - if let Poll::Ready(x) = a.poll(cx) { - return Poll::Ready(Either3::First(x)); - } - if let Poll::Ready(x) = b.poll(cx) { - return Poll::Ready(Either3::Second(x)); - } - if let Poll::Ready(x) = c.poll(cx) { - return Poll::Ready(Either3::Third(x)); - } - Poll::Pending - } -} - pub struct Pending { _phantom: PhantomData, }