diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index ff712930..1843bbae 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -29,6 +29,8 @@ use crate::blocking_mutex::raw::RawMutex; use crate::blocking_mutex::Mutex; use crate::waitqueue::WakerRegistration; +pub mod priority; + /// Send-only access to a [`Channel`]. pub struct Sender<'ch, M, T, const N: usize> where @@ -76,7 +78,7 @@ where /// Send-only access to a [`Channel`] without knowing channel size. pub struct DynamicSender<'ch, T> { - pub(crate) channel: &'ch dyn DynamicChannel, + channel: &'ch dyn DynamicChannel, } impl<'ch, T> Clone for DynamicSender<'ch, T> { @@ -176,7 +178,7 @@ where /// Receive-only access to a [`Channel`] without knowing channel size. pub struct DynamicReceiver<'ch, T> { - pub(crate) channel: &'ch dyn DynamicChannel, + channel: &'ch dyn DynamicChannel, } impl<'ch, T> Clone for DynamicReceiver<'ch, T> { @@ -321,7 +323,7 @@ impl<'ch, T> Future for DynamicSendFuture<'ch, T> { impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} -pub(crate) trait DynamicChannel { +trait DynamicChannel { fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError>; fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result; diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/channel/priority.rs similarity index 92% rename from embassy-sync/src/priority_channel.rs rename to embassy-sync/src/channel/priority.rs index 14366281..1fd137db 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/channel/priority.rs @@ -183,23 +183,6 @@ where } } -/// Future returned by [`DynamicReceiver::receive`]. -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct DynamicReceiveFuture<'ch, T> { - channel: &'ch dyn DynamicChannel, -} - -impl<'ch, T> Future for DynamicReceiveFuture<'ch, T> { - type Output = T; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.channel.try_receive_with_context(Some(cx)) { - Ok(v) => Poll::Ready(v), - Err(TryReceiveError::Empty) => Poll::Pending, - } - } -} - /// Future returned by [`PriorityChannel::send`] and [`Sender::send`]. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct SendFuture<'ch, M, T, K, const N: usize> @@ -242,32 +225,6 @@ where { } -/// Future returned by [`DynamicSender::send`]. -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct DynamicSendFuture<'ch, T> { - channel: &'ch dyn DynamicChannel, - message: Option, -} - -impl<'ch, T> Future for DynamicSendFuture<'ch, T> { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.message.take() { - Some(m) => match self.channel.try_send_with_context(m, Some(cx)) { - Ok(..) => Poll::Ready(()), - Err(TrySendError::Full(m)) => { - self.message = Some(m); - Poll::Pending - } - }, - None => panic!("Message cannot be None"), - } - } -} - -impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} - struct ChannelState { queue: BinaryHeap, receiver_waker: WakerRegistration, @@ -386,7 +343,7 @@ where /// /// ``` /// # use heapless::binary_heap::Max; - /// use embassy_sync::priority_channel::PriorityChannel; + /// use embassy_sync::channel::priority::PriorityChannel; /// use embassy_sync::blocking_mutex::raw::NoopRawMutex; /// /// // Declare a bounded channel of 3 u32s. diff --git a/embassy-sync/src/lib.rs b/embassy-sync/src/lib.rs index 3ffcb913..c40fa3b6 100644 --- a/embassy-sync/src/lib.rs +++ b/embassy-sync/src/lib.rs @@ -15,7 +15,6 @@ pub mod blocking_mutex; pub mod channel; pub mod mutex; pub mod pipe; -pub mod priority_channel; pub mod pubsub; pub mod signal; pub mod waitqueue;