aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/pubsub
diff options
context:
space:
mode:
authorCurly <[email protected]>2025-08-19 22:30:53 -0700
committerCurly <[email protected]>2025-08-19 22:36:49 -0700
commit368738bef44dbba1a178383d878a6d9423b1ccd9 (patch)
tree4c375e7ec4615e6dee9fda837584067d19b7caf6 /embassy-sync/src/pubsub
parenta5cb04bdab602bc3bd056d254a9d61cad55bd967 (diff)
chore: add more `Debug` impls to `embassy-sync`, particularly on `OnceLock`
All tests green
Diffstat (limited to 'embassy-sync/src/pubsub')
-rw-r--r--embassy-sync/src/pubsub/mod.rs2
-rw-r--r--embassy-sync/src/pubsub/publisher.rs6
-rw-r--r--embassy-sync/src/pubsub/subscriber.rs3
3 files changed, 11 insertions, 0 deletions
diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs
index 9206b9383..ad9402f5a 100644
--- a/embassy-sync/src/pubsub/mod.rs
+++ b/embassy-sync/src/pubsub/mod.rs
@@ -71,6 +71,7 @@ pub use subscriber::{DynSubscriber, Subscriber};
71/// # block_on(test); 71/// # block_on(test);
72/// ``` 72/// ```
73/// 73///
74#[derive(Debug)]
74pub struct PubSubChannel<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> { 75pub struct PubSubChannel<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> {
75 inner: Mutex<M, RefCell<PubSubState<T, CAP, SUBS, PUBS>>>, 76 inner: Mutex<M, RefCell<PubSubState<T, CAP, SUBS, PUBS>>>,
76} 77}
@@ -297,6 +298,7 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi
297} 298}
298 299
299/// Internal state for the PubSub channel 300/// Internal state for the PubSub channel
301#[derive(Debug)]
300struct PubSubState<T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> { 302struct PubSubState<T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> {
301 /// The queue contains the last messages that have been published and a countdown of how many subscribers are yet to read it 303 /// The queue contains the last messages that have been published and a countdown of how many subscribers are yet to read it
302 queue: Deque<(T, usize), CAP>, 304 queue: Deque<(T, usize), CAP>,
diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs
index 52a52f926..2a67a0002 100644
--- a/embassy-sync/src/pubsub/publisher.rs
+++ b/embassy-sync/src/pubsub/publisher.rs
@@ -10,6 +10,7 @@ use super::{PubSubBehavior, PubSubChannel};
10use crate::blocking_mutex::raw::RawMutex; 10use crate::blocking_mutex::raw::RawMutex;
11 11
12/// A publisher to a channel 12/// A publisher to a channel
13#[derive(Debug)]
13pub struct Pub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 14pub struct Pub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
14 /// The channel we are a publisher for 15 /// The channel we are a publisher for
15 channel: &'a PSB, 16 channel: &'a PSB,
@@ -106,6 +107,7 @@ impl<'a, T: Clone> DerefMut for DynPublisher<'a, T> {
106} 107}
107 108
108/// A publisher that holds a generic reference to the channel 109/// A publisher that holds a generic reference to the channel
110#[derive(Debug)]
109pub struct Publisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( 111pub struct Publisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>(
110 pub(super) Pub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>, 112 pub(super) Pub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>,
111); 113);
@@ -130,6 +132,7 @@ impl<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS:
130 132
131/// A publisher that can only use the `publish_immediate` function, but it doesn't have to be registered with the channel. 133/// A publisher that can only use the `publish_immediate` function, but it doesn't have to be registered with the channel.
132/// (So an infinite amount is possible) 134/// (So an infinite amount is possible)
135#[derive(Debug)]
133pub struct ImmediatePub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 136pub struct ImmediatePub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
134 /// The channel we are a publisher for 137 /// The channel we are a publisher for
135 channel: &'a PSB, 138 channel: &'a PSB,
@@ -205,6 +208,7 @@ impl<'a, T: Clone> DerefMut for DynImmediatePublisher<'a, T> {
205} 208}
206 209
207/// An immediate publisher that holds a generic reference to the channel 210/// An immediate publisher that holds a generic reference to the channel
211#[derive(Debug)]
208pub struct ImmediatePublisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( 212pub struct ImmediatePublisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>(
209 pub(super) ImmediatePub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>, 213 pub(super) ImmediatePub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>,
210); 214);
@@ -229,6 +233,7 @@ impl<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS:
229 233
230#[must_use = "Sinks do nothing unless polled"] 234#[must_use = "Sinks do nothing unless polled"]
231/// [`futures_sink::Sink`] adapter for [`Pub`]. 235/// [`futures_sink::Sink`] adapter for [`Pub`].
236#[derive(Debug)]
232pub struct PubSink<'a, 'p, PSB, T> 237pub struct PubSink<'a, 'p, PSB, T>
233where 238where
234 T: Clone, 239 T: Clone,
@@ -290,6 +295,7 @@ where
290 295
291/// Future for the publisher wait action 296/// Future for the publisher wait action
292#[must_use = "futures do nothing unless you `.await` or poll them"] 297#[must_use = "futures do nothing unless you `.await` or poll them"]
298#[derive(Debug)]
293pub struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 299pub struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
294 /// The message we need to publish 300 /// The message we need to publish
295 message: Option<T>, 301 message: Option<T>,
diff --git a/embassy-sync/src/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs
index 649382cf1..356de23f6 100644
--- a/embassy-sync/src/pubsub/subscriber.rs
+++ b/embassy-sync/src/pubsub/subscriber.rs
@@ -10,6 +10,7 @@ use super::{PubSubBehavior, PubSubChannel, WaitResult};
10use crate::blocking_mutex::raw::RawMutex; 10use crate::blocking_mutex::raw::RawMutex;
11 11
12/// A subscriber to a channel 12/// A subscriber to a channel
13#[derive(Debug)]
13pub struct Sub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 14pub struct Sub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
14 /// The message id of the next message we are yet to receive 15 /// The message id of the next message we are yet to receive
15 next_message_id: u64, 16 next_message_id: u64,
@@ -151,6 +152,7 @@ impl<'a, T: Clone> DerefMut for DynSubscriber<'a, T> {
151} 152}
152 153
153/// A subscriber that holds a generic reference to the channel 154/// A subscriber that holds a generic reference to the channel
155#[derive(Debug)]
154pub struct Subscriber<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( 156pub struct Subscriber<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>(
155 pub(super) Sub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>, 157 pub(super) Sub<'a, PubSubChannel<M, T, CAP, SUBS, PUBS>, T>,
156); 158);
@@ -175,6 +177,7 @@ impl<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS:
175 177
176/// Future for the subscriber wait action 178/// Future for the subscriber wait action
177#[must_use = "futures do nothing unless you `.await` or poll them"] 179#[must_use = "futures do nothing unless you `.await` or poll them"]
180#[derive(Debug)]
178pub struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { 181pub struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> {
179 subscriber: &'s mut Sub<'a, PSB, T>, 182 subscriber: &'s mut Sub<'a, PSB, T>,
180} 183}