aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/channel.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-03-12 15:27:52 +0100
committerUlf Lilleengen <[email protected]>2024-03-12 15:27:52 +0100
commit8bb1fe1f653bd4bef6ad0760f33a07bcfe5d91fb (patch)
tree48f6bf5b35c3e4e92da9772a5cc8b8c979ba09d2 /embassy-sync/src/channel.rs
parent1ef02e538497d1876ec26f8acf0763d6c3263382 (diff)
Add conversion into dyn variants for channel futures
Diffstat (limited to 'embassy-sync/src/channel.rs')
-rw-r--r--embassy-sync/src/channel.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 01db0d09a..79d3e0378 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -263,6 +263,15 @@ impl<'ch, T> Future for DynamicReceiveFuture<'ch, T> {
263 } 263 }
264} 264}
265 265
266impl<'ch, M: RawMutex, T, const N: usize> From<ReceiveFuture<'ch, M, T, N>> for DynamicReceiveFuture<'ch, T>
267{
268 fn from(value: ReceiveFuture<'ch, M, T, N>) -> Self {
269 Self {
270 channel: value.channel,
271 }
272 }
273}
274
266/// Future returned by [`Channel::send`] and [`Sender::send`]. 275/// Future returned by [`Channel::send`] and [`Sender::send`].
267#[must_use = "futures do nothing unless you `.await` or poll them"] 276#[must_use = "futures do nothing unless you `.await` or poll them"]
268pub struct SendFuture<'ch, M, T, const N: usize> 277pub struct SendFuture<'ch, M, T, const N: usize>
@@ -321,6 +330,16 @@ impl<'ch, T> Future for DynamicSendFuture<'ch, T> {
321 330
322impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} 331impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {}
323 332
333impl<'ch, M: RawMutex, T, const N: usize> From<SendFuture<'ch, M, T, N>> for DynamicSendFuture<'ch, T>
334{
335 fn from(value: SendFuture<'ch, M, T, N>) -> Self {
336 Self {
337 channel: value.channel,
338 message: value.message,
339 }
340 }
341}
342
324pub(crate) trait DynamicChannel<T> { 343pub(crate) trait DynamicChannel<T> {
325 fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>; 344 fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError<T>>;
326 345