aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-04-11 13:33:48 +0200
committerUlf Lilleengen <[email protected]>2022-04-11 13:33:48 +0200
commitcdf30e68eb8e91ef13ad6195bea42bf75c9d3018 (patch)
treef7ffc0c8a2541edf8eb42d935a13a73097621d2f
parentbc1dff34c0e5d44706c6387892d8f2c2f3539bd9 (diff)
Erase mutex type as well
-rw-r--r--embassy/src/channel/channel.rs79
1 files changed, 23 insertions, 56 deletions
diff --git a/embassy/src/channel/channel.rs b/embassy/src/channel/channel.rs
index c7a89793a..a1d805c53 100644
--- a/embassy/src/channel/channel.rs
+++ b/embassy/src/channel/channel.rs
@@ -68,17 +68,11 @@ where
68 68
69/// Send-only access to a [`Channel`] without knowing channel size. 69/// Send-only access to a [`Channel`] without knowing channel size.
70#[derive(Copy)] 70#[derive(Copy)]
71pub struct DynamicSender<'ch, M, T> 71pub struct DynamicSender<'ch, T> {
72where 72 channel: &'ch dyn DynamicChannel<T>,
73 M: RawMutex,
74{
75 channel: &'ch dyn DynamicChannel<M, T>,
76} 73}
77 74
78impl<'ch, M, T> Clone for DynamicSender<'ch, M, T> 75impl<'ch, T> Clone for DynamicSender<'ch, T> {
79where
80 M: RawMutex,
81{
82 fn clone(&self) -> Self { 76 fn clone(&self) -> Self {
83 DynamicSender { 77 DynamicSender {
84 channel: self.channel, 78 channel: self.channel,
@@ -86,7 +80,7 @@ where
86 } 80 }
87} 81}
88 82
89impl<'ch, M, T, const N: usize> From<Sender<'ch, M, T, N>> for DynamicSender<'ch, M, T> 83impl<'ch, M, T, const N: usize> From<Sender<'ch, M, T, N>> for DynamicSender<'ch, T>
90where 84where
91 M: RawMutex, 85 M: RawMutex,
92{ 86{
@@ -95,14 +89,11 @@ where
95 } 89 }
96} 90}
97 91
98impl<'ch, M, T> DynamicSender<'ch, M, T> 92impl<'ch, T> DynamicSender<'ch, T> {
99where
100 M: RawMutex,
101{
102 /// Sends a value. 93 /// Sends a value.
103 /// 94 ///
104 /// See [`Channel::send()`] 95 /// See [`Channel::send()`]
105 pub fn send(&self, message: T) -> DynamicSendFuture<'ch, M, T> { 96 pub fn send(&self, message: T) -> DynamicSendFuture<'ch, T> {
106 DynamicSendFuture { 97 DynamicSendFuture {
107 channel: self.channel, 98 channel: self.channel,
108 message: Some(message), 99 message: Some(message),
@@ -158,17 +149,11 @@ where
158 149
159/// Receive-only access to a [`Channel`] without knowing channel size. 150/// Receive-only access to a [`Channel`] without knowing channel size.
160#[derive(Copy)] 151#[derive(Copy)]
161pub struct DynamicReceiver<'ch, M, T> 152pub struct DynamicReceiver<'ch, T> {
162where 153 channel: &'ch dyn DynamicChannel<T>,
163 M: RawMutex,
164{
165 channel: &'ch dyn DynamicChannel<M, T>,
166} 154}
167 155
168impl<'ch, M, T> Clone for DynamicReceiver<'ch, M, T> 156impl<'ch, T> Clone for DynamicReceiver<'ch, T> {
169where
170 M: RawMutex,
171{
172 fn clone(&self) -> Self { 157 fn clone(&self) -> Self {
173 DynamicReceiver { 158 DynamicReceiver {
174 channel: self.channel, 159 channel: self.channel,
@@ -176,14 +161,11 @@ where
176 } 161 }
177} 162}
178 163
179impl<'ch, M, T> DynamicReceiver<'ch, M, T> 164impl<'ch, T> DynamicReceiver<'ch, T> {
180where
181 M: RawMutex,
182{
183 /// Receive the next value. 165 /// Receive the next value.
184 /// 166 ///
185 /// See [`Channel::recv()`]. 167 /// See [`Channel::recv()`].
186 pub fn recv(&self) -> DynamicRecvFuture<'_, M, T> { 168 pub fn recv(&self) -> DynamicRecvFuture<'_, T> {
187 DynamicRecvFuture { 169 DynamicRecvFuture {
188 channel: self.channel, 170 channel: self.channel,
189 } 171 }
@@ -197,7 +179,7 @@ where
197 } 179 }
198} 180}
199 181
200impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, M, T> 182impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, T>
201where 183where
202 M: RawMutex, 184 M: RawMutex,
203{ 185{
@@ -227,17 +209,11 @@ where
227 } 209 }
228} 210}
229 211
230pub struct DynamicRecvFuture<'ch, M, T> 212pub struct DynamicRecvFuture<'ch, T> {
231where 213 channel: &'ch dyn DynamicChannel<T>,
232 M: RawMutex,
233{
234 channel: &'ch dyn DynamicChannel<M, T>,
235} 214}
236 215
237impl<'ch, M, T> Future for DynamicRecvFuture<'ch, M, T> 216impl<'ch, T> Future for DynamicRecvFuture<'ch, T> {
238where
239 M: RawMutex,
240{
241 type Output = T; 217 type Output = T;
242 218
243 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { 219 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
@@ -278,18 +254,12 @@ where
278 254
279impl<'ch, M, T, const N: usize> Unpin for SendFuture<'ch, M, T, N> where M: RawMutex {} 255impl<'ch, M, T, const N: usize> Unpin for SendFuture<'ch, M, T, N> where M: RawMutex {}
280 256
281pub struct DynamicSendFuture<'ch, M, T> 257pub struct DynamicSendFuture<'ch, T> {
282where 258 channel: &'ch dyn DynamicChannel<T>,
283 M: RawMutex,
284{
285 channel: &'ch dyn DynamicChannel<M, T>,
286 message: Option<T>, 259 message: Option<T>,
287} 260}
288 261
289impl<'ch, M, T> Future for DynamicSendFuture<'ch, M, T> 262impl<'ch, T> Future for DynamicSendFuture<'ch, T> {
290where
291 M: RawMutex,
292{
293 type Output = (); 263 type Output = ();
294 264
295 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 265 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
@@ -306,12 +276,9 @@ where
306 } 276 }
307} 277}
308 278
309impl<'ch, M, T> Unpin for DynamicSendFuture<'ch, M, T> where M: RawMutex {} 279impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {}
310 280
311trait DynamicChannel<M, T> 281trait DynamicChannel<T> {
312where
313 M: RawMutex,
314{
315 fn try_send_with_context( 282 fn try_send_with_context(
316 &self, 283 &self,
317 message: T, 284 message: T,
@@ -517,7 +484,7 @@ where
517 484
518/// Implements the DynamicChannel to allow creating types that are unaware of the queue size with the 485/// Implements the DynamicChannel to allow creating types that are unaware of the queue size with the
519/// tradeoff cost of dynamic dispatch. 486/// tradeoff cost of dynamic dispatch.
520impl<M, T, const N: usize> DynamicChannel<M, T> for Channel<M, T, N> 487impl<M, T, const N: usize> DynamicChannel<T> for Channel<M, T, N>
521where 488where
522 M: RawMutex, 489 M: RawMutex,
523{ 490{
@@ -609,8 +576,8 @@ mod tests {
609 #[test] 576 #[test]
610 fn dynamic_dispatch() { 577 fn dynamic_dispatch() {
611 let c = Channel::<NoopRawMutex, u32, 3>::new(); 578 let c = Channel::<NoopRawMutex, u32, 3>::new();
612 let s: DynamicSender<'_, NoopRawMutex, u32> = c.sender().into(); 579 let s: DynamicSender<'_, u32> = c.sender().into();
613 let r: DynamicReceiver<'_, NoopRawMutex, u32> = c.receiver().into(); 580 let r: DynamicReceiver<'_, u32> = c.receiver().into();
614 581
615 assert!(s.try_send(1).is_ok()); 582 assert!(s.try_send(1).is_ok());
616 assert_eq!(r.try_recv().unwrap(), 1); 583 assert_eq!(r.try_recv().unwrap(), 1);