diff options
| author | Ulf Lilleengen <[email protected]> | 2024-09-19 12:55:50 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-19 12:55:50 +0000 |
| commit | d7780fcf83a8a35d7b09e5df7b62dd8218436715 (patch) | |
| tree | febe2a9851e133f88c948f034a3ec3a49112be0a | |
| parent | cdb44f1272e9264324cc866ee2d141301e968e10 (diff) | |
| parent | 893b8d79e8bab8dae0f46a0182443df9160592b5 (diff) | |
Merge pull request #3354 from mammothbane/main
embassy_sync/pubsub: fix PubSubBehavior visibility
| -rw-r--r-- | embassy-sync/src/pubsub/mod.rs | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs index a97eb7d5b..812302e2b 100644 --- a/embassy-sync/src/pubsub/mod.rs +++ b/embassy-sync/src/pubsub/mod.rs | |||
| @@ -194,6 +194,25 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> crate::pubsub::PubSubBehavior<T> | ||
| 198 | for PubSubChannel<M, T, CAP, SUBS, PUBS> | ||
| 199 | { | ||
| 200 | fn publish_immediate(&self, message: T) { | ||
| 201 | self.inner.lock(|s| { | ||
| 202 | let mut s = s.borrow_mut(); | ||
| 203 | s.publish_immediate(message) | ||
| 204 | }) | ||
| 205 | } | ||
| 206 | |||
| 207 | fn capacity(&self) -> usize { | ||
| 208 | self.capacity() | ||
| 209 | } | ||
| 210 | |||
| 211 | fn is_full(&self) -> bool { | ||
| 212 | self.is_full() | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 197 | impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> SealedPubSubBehavior<T> | 216 | impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> SealedPubSubBehavior<T> |
| 198 | for PubSubChannel<M, T, CAP, SUBS, PUBS> | 217 | for PubSubChannel<M, T, CAP, SUBS, PUBS> |
| 199 | { | 218 | { |
| @@ -246,13 +265,6 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 246 | }) | 265 | }) |
| 247 | } | 266 | } |
| 248 | 267 | ||
| 249 | fn publish_immediate(&self, message: T) { | ||
| 250 | self.inner.lock(|s| { | ||
| 251 | let mut s = s.borrow_mut(); | ||
| 252 | s.publish_immediate(message) | ||
| 253 | }) | ||
| 254 | } | ||
| 255 | |||
| 256 | fn unregister_subscriber(&self, subscriber_next_message_id: u64) { | 268 | fn unregister_subscriber(&self, subscriber_next_message_id: u64) { |
| 257 | self.inner.lock(|s| { | 269 | self.inner.lock(|s| { |
| 258 | let mut s = s.borrow_mut(); | 270 | let mut s = s.borrow_mut(); |
| @@ -267,10 +279,6 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 267 | }) | 279 | }) |
| 268 | } | 280 | } |
| 269 | 281 | ||
| 270 | fn capacity(&self) -> usize { | ||
| 271 | self.capacity() | ||
| 272 | } | ||
| 273 | |||
| 274 | fn free_capacity(&self) -> usize { | 282 | fn free_capacity(&self) -> usize { |
| 275 | self.free_capacity() | 283 | self.free_capacity() |
| 276 | } | 284 | } |
| @@ -286,10 +294,6 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 286 | fn is_empty(&self) -> bool { | 294 | fn is_empty(&self) -> bool { |
| 287 | self.is_empty() | 295 | self.is_empty() |
| 288 | } | 296 | } |
| 289 | |||
| 290 | fn is_full(&self) -> bool { | ||
| 291 | self.is_full() | ||
| 292 | } | ||
| 293 | } | 297 | } |
| 294 | 298 | ||
| 295 | /// Internal state for the PubSub channel | 299 | /// Internal state for the PubSub channel |
| @@ -445,8 +449,6 @@ pub enum Error { | |||
| 445 | MaximumPublishersReached, | 449 | MaximumPublishersReached, |
| 446 | } | 450 | } |
| 447 | 451 | ||
| 448 | /// 'Middle level' behaviour of the pubsub channel. | ||
| 449 | /// This trait is used so that Sub and Pub can be generic over the channel. | ||
| 450 | trait SealedPubSubBehavior<T> { | 452 | trait SealedPubSubBehavior<T> { |
| 451 | /// Try to get a message from the queue with the given message id. | 453 | /// Try to get a message from the queue with the given message id. |
| 452 | /// | 454 | /// |
| @@ -462,12 +464,6 @@ trait SealedPubSubBehavior<T> { | |||
| 462 | /// If the queue is full and a context is given, then its waker is registered in the publisher wakers. | 464 | /// If the queue is full and a context is given, then its waker is registered in the publisher wakers. |
| 463 | fn publish_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), T>; | 465 | fn publish_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), T>; |
| 464 | 466 | ||
| 465 | /// Publish a message immediately | ||
| 466 | fn publish_immediate(&self, message: T); | ||
| 467 | |||
| 468 | /// Returns the maximum number of elements the channel can hold. | ||
| 469 | fn capacity(&self) -> usize; | ||
| 470 | |||
| 471 | /// Returns the free capacity of the channel. | 467 | /// Returns the free capacity of the channel. |
| 472 | /// | 468 | /// |
| 473 | /// This is equivalent to `capacity() - len()` | 469 | /// This is equivalent to `capacity() - len()` |
| @@ -482,9 +478,6 @@ trait SealedPubSubBehavior<T> { | |||
| 482 | /// Returns whether the channel is empty. | 478 | /// Returns whether the channel is empty. |
| 483 | fn is_empty(&self) -> bool; | 479 | fn is_empty(&self) -> bool; |
| 484 | 480 | ||
| 485 | /// Returns whether the channel is full. | ||
| 486 | fn is_full(&self) -> bool; | ||
| 487 | |||
| 488 | /// Let the channel know that a subscriber has dropped | 481 | /// Let the channel know that a subscriber has dropped |
| 489 | fn unregister_subscriber(&self, subscriber_next_message_id: u64); | 482 | fn unregister_subscriber(&self, subscriber_next_message_id: u64); |
| 490 | 483 | ||
| @@ -495,9 +488,16 @@ trait SealedPubSubBehavior<T> { | |||
| 495 | /// 'Middle level' behaviour of the pubsub channel. | 488 | /// 'Middle level' behaviour of the pubsub channel. |
| 496 | /// This trait is used so that Sub and Pub can be generic over the channel. | 489 | /// This trait is used so that Sub and Pub can be generic over the channel. |
| 497 | #[allow(private_bounds)] | 490 | #[allow(private_bounds)] |
| 498 | pub trait PubSubBehavior<T>: SealedPubSubBehavior<T> {} | 491 | pub trait PubSubBehavior<T>: SealedPubSubBehavior<T> { |
| 492 | /// Publish a message immediately | ||
| 493 | fn publish_immediate(&self, message: T); | ||
| 499 | 494 | ||
| 500 | impl<T, C: SealedPubSubBehavior<T>> PubSubBehavior<T> for C {} | 495 | /// Returns the maximum number of elements the channel can hold. |
| 496 | fn capacity(&self) -> usize; | ||
| 497 | |||
| 498 | /// Returns whether the channel is full. | ||
| 499 | fn is_full(&self) -> bool; | ||
| 500 | } | ||
| 501 | 501 | ||
| 502 | /// The result of the subscriber wait procedure | 502 | /// The result of the subscriber wait procedure |
| 503 | #[derive(Debug, Clone, PartialEq, Eq)] | 503 | #[derive(Debug, Clone, PartialEq, Eq)] |
