aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/pubsub
diff options
context:
space:
mode:
authorNathan Perry <[email protected]>2024-09-19 08:17:33 -0400
committerNathan Perry <[email protected]>2024-09-19 08:44:45 -0400
commit893b8d79e8bab8dae0f46a0182443df9160592b5 (patch)
treefebe2a9851e133f88c948f034a3ec3a49112be0a /embassy-sync/src/pubsub
parentcdb44f1272e9264324cc866ee2d141301e968e10 (diff)
embassy_sync/pubsub: fix PubSubBehavior visibility
https://github.com/embassy-rs/embassy/pull/2969 appears to have broken direct `publish_immediate()` on `pubsub::Channel`, as it functionally made `PubSubBehavior` private and didn't delegate this method to the new (private) `SealedPubSubBehavior`. This change moves `publish_immediate`, `capacity`, and `is_full` from `SealedPubSubBehavior` to `PubSubBehavior` in order to restore them to `pub` visibility.
Diffstat (limited to 'embassy-sync/src/pubsub')
-rw-r--r--embassy-sync/src/pubsub/mod.rs56
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
197impl<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
197impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> SealedPubSubBehavior<T> 216impl<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.
450trait SealedPubSubBehavior<T> { 452trait 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)]
498pub trait PubSubBehavior<T>: SealedPubSubBehavior<T> {} 491pub trait PubSubBehavior<T>: SealedPubSubBehavior<T> {
492 /// Publish a message immediately
493 fn publish_immediate(&self, message: T);
499 494
500impl<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)]