diff options
| author | Ulf Lilleengen <[email protected]> | 2022-04-11 13:33:48 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-04-11 13:33:48 +0200 |
| commit | cdf30e68eb8e91ef13ad6195bea42bf75c9d3018 (patch) | |
| tree | f7ffc0c8a2541edf8eb42d935a13a73097621d2f | |
| parent | bc1dff34c0e5d44706c6387892d8f2c2f3539bd9 (diff) | |
Erase mutex type as well
| -rw-r--r-- | embassy/src/channel/channel.rs | 79 |
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)] |
| 71 | pub struct DynamicSender<'ch, M, T> | 71 | pub struct DynamicSender<'ch, T> { |
| 72 | where | 72 | channel: &'ch dyn DynamicChannel<T>, |
| 73 | M: RawMutex, | ||
| 74 | { | ||
| 75 | channel: &'ch dyn DynamicChannel<M, T>, | ||
| 76 | } | 73 | } |
| 77 | 74 | ||
| 78 | impl<'ch, M, T> Clone for DynamicSender<'ch, M, T> | 75 | impl<'ch, T> Clone for DynamicSender<'ch, T> { |
| 79 | where | ||
| 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 | ||
| 89 | impl<'ch, M, T, const N: usize> From<Sender<'ch, M, T, N>> for DynamicSender<'ch, M, T> | 83 | impl<'ch, M, T, const N: usize> From<Sender<'ch, M, T, N>> for DynamicSender<'ch, T> |
| 90 | where | 84 | where |
| 91 | M: RawMutex, | 85 | M: RawMutex, |
| 92 | { | 86 | { |
| @@ -95,14 +89,11 @@ where | |||
| 95 | } | 89 | } |
| 96 | } | 90 | } |
| 97 | 91 | ||
| 98 | impl<'ch, M, T> DynamicSender<'ch, M, T> | 92 | impl<'ch, T> DynamicSender<'ch, T> { |
| 99 | where | ||
| 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)] |
| 161 | pub struct DynamicReceiver<'ch, M, T> | 152 | pub struct DynamicReceiver<'ch, T> { |
| 162 | where | 153 | channel: &'ch dyn DynamicChannel<T>, |
| 163 | M: RawMutex, | ||
| 164 | { | ||
| 165 | channel: &'ch dyn DynamicChannel<M, T>, | ||
| 166 | } | 154 | } |
| 167 | 155 | ||
| 168 | impl<'ch, M, T> Clone for DynamicReceiver<'ch, M, T> | 156 | impl<'ch, T> Clone for DynamicReceiver<'ch, T> { |
| 169 | where | ||
| 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 | ||
| 179 | impl<'ch, M, T> DynamicReceiver<'ch, M, T> | 164 | impl<'ch, T> DynamicReceiver<'ch, T> { |
| 180 | where | ||
| 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 | ||
| 200 | impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, M, T> | 182 | impl<'ch, M, T, const N: usize> From<Receiver<'ch, M, T, N>> for DynamicReceiver<'ch, T> |
| 201 | where | 183 | where |
| 202 | M: RawMutex, | 184 | M: RawMutex, |
| 203 | { | 185 | { |
| @@ -227,17 +209,11 @@ where | |||
| 227 | } | 209 | } |
| 228 | } | 210 | } |
| 229 | 211 | ||
| 230 | pub struct DynamicRecvFuture<'ch, M, T> | 212 | pub struct DynamicRecvFuture<'ch, T> { |
| 231 | where | 213 | channel: &'ch dyn DynamicChannel<T>, |
| 232 | M: RawMutex, | ||
| 233 | { | ||
| 234 | channel: &'ch dyn DynamicChannel<M, T>, | ||
| 235 | } | 214 | } |
| 236 | 215 | ||
| 237 | impl<'ch, M, T> Future for DynamicRecvFuture<'ch, M, T> | 216 | impl<'ch, T> Future for DynamicRecvFuture<'ch, T> { |
| 238 | where | ||
| 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 | ||
| 279 | impl<'ch, M, T, const N: usize> Unpin for SendFuture<'ch, M, T, N> where M: RawMutex {} | 255 | impl<'ch, M, T, const N: usize> Unpin for SendFuture<'ch, M, T, N> where M: RawMutex {} |
| 280 | 256 | ||
| 281 | pub struct DynamicSendFuture<'ch, M, T> | 257 | pub struct DynamicSendFuture<'ch, T> { |
| 282 | where | 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 | ||
| 289 | impl<'ch, M, T> Future for DynamicSendFuture<'ch, M, T> | 262 | impl<'ch, T> Future for DynamicSendFuture<'ch, T> { |
| 290 | where | ||
| 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 | ||
| 309 | impl<'ch, M, T> Unpin for DynamicSendFuture<'ch, M, T> where M: RawMutex {} | 279 | impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} |
| 310 | 280 | ||
| 311 | trait DynamicChannel<M, T> | 281 | trait DynamicChannel<T> { |
| 312 | where | ||
| 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. |
| 520 | impl<M, T, const N: usize> DynamicChannel<M, T> for Channel<M, T, N> | 487 | impl<M, T, const N: usize> DynamicChannel<T> for Channel<M, T, N> |
| 521 | where | 488 | where |
| 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); |
