diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 11561430..102ccbb3 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 4fc55461..3f20262c 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, }