aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-04-07 15:15:44 +0200
committerUlf Lilleengen <[email protected]>2022-04-07 15:15:44 +0200
commit9206584aa9af14a7fee8af4d07be096f8c7facce (patch)
treecfb5b09b9e3e42d99fbec78bdc251ec8d1513c8f
parentfee0aef076718adcb2c654920712aa20786c94be (diff)
Add back support for cloning sender/receiver
* Remove level of import indirection for Channel and Signal.
-rw-r--r--embassy/src/channel/channel.rs36
-rw-r--r--embassy/src/channel/mod.rs3
2 files changed, 37 insertions, 2 deletions
diff --git a/embassy/src/channel/channel.rs b/embassy/src/channel/channel.rs
index 9084cd57b..d749e5971 100644
--- a/embassy/src/channel/channel.rs
+++ b/embassy/src/channel/channel.rs
@@ -28,7 +28,7 @@ use crate::blocking_mutex::Mutex;
28use crate::waitqueue::WakerRegistration; 28use crate::waitqueue::WakerRegistration;
29 29
30/// Send-only access to a [`Channel`]. 30/// Send-only access to a [`Channel`].
31#[derive(Copy, Clone)] 31#[derive(Copy)]
32pub struct Sender<'ch, M, T, const N: usize> 32pub struct Sender<'ch, M, T, const N: usize>
33where 33where
34 M: RawMutex, 34 M: RawMutex,
@@ -36,6 +36,17 @@ where
36 channel: &'ch Channel<M, T, N>, 36 channel: &'ch Channel<M, T, N>,
37} 37}
38 38
39impl<'ch, M, T, const N: usize> Clone for Sender<'ch, M, T, N>
40where
41 M: RawMutex,
42{
43 fn clone(&self) -> Self {
44 Sender {
45 channel: self.channel,
46 }
47 }
48}
49
39impl<'ch, M, T, const N: usize> Sender<'ch, M, T, N> 50impl<'ch, M, T, const N: usize> Sender<'ch, M, T, N>
40where 51where
41 M: RawMutex, 52 M: RawMutex,
@@ -56,7 +67,7 @@ where
56} 67}
57 68
58/// Receive-only access to a [`Channel`]. 69/// Receive-only access to a [`Channel`].
59#[derive(Copy, Clone)] 70#[derive(Copy)]
60pub struct Receiver<'ch, M, T, const N: usize> 71pub struct Receiver<'ch, M, T, const N: usize>
61where 72where
62 M: RawMutex, 73 M: RawMutex,
@@ -64,6 +75,17 @@ where
64 channel: &'ch Channel<M, T, N>, 75 channel: &'ch Channel<M, T, N>,
65} 76}
66 77
78impl<'ch, M, T, const N: usize> Clone for Receiver<'ch, M, T, N>
79where
80 M: RawMutex,
81{
82 fn clone(&self) -> Self {
83 Receiver {
84 channel: self.channel,
85 }
86 }
87}
88
67impl<'ch, M, T, const N: usize> Receiver<'ch, M, T, N> 89impl<'ch, M, T, const N: usize> Receiver<'ch, M, T, N>
68where 90where
69 M: RawMutex, 91 M: RawMutex,
@@ -379,6 +401,16 @@ mod tests {
379 assert_eq!(c.try_recv().unwrap(), 1); 401 assert_eq!(c.try_recv().unwrap(), 1);
380 } 402 }
381 403
404 #[test]
405 fn cloning() {
406 let c = Channel::<NoopRawMutex, u32, 3>::new();
407 let r1 = c.receiver();
408 let s1 = c.sender();
409
410 let _ = r1.clone();
411 let _ = s1.clone();
412 }
413
382 #[futures_test::test] 414 #[futures_test::test]
383 async fn receiver_receives_given_try_send_async() { 415 async fn receiver_receives_given_try_send_async() {
384 let executor = ThreadPool::new().unwrap(); 416 let executor = ThreadPool::new().unwrap();
diff --git a/embassy/src/channel/mod.rs b/embassy/src/channel/mod.rs
index e51a442df..4d37fe859 100644
--- a/embassy/src/channel/mod.rs
+++ b/embassy/src/channel/mod.rs
@@ -1,4 +1,7 @@
1//! Async channels 1//! Async channels
2 2
3pub mod channel; 3pub mod channel;
4pub use channel::*;
5
4pub mod signal; 6pub mod signal;
7pub use signal::*;