diff options
| author | Curly <[email protected]> | 2025-08-19 22:30:53 -0700 |
|---|---|---|
| committer | Curly <[email protected]> | 2025-08-19 22:36:49 -0700 |
| commit | 368738bef44dbba1a178383d878a6d9423b1ccd9 (patch) | |
| tree | 4c375e7ec4615e6dee9fda837584067d19b7caf6 /embassy-sync/src/pubsub | |
| parent | a5cb04bdab602bc3bd056d254a9d61cad55bd967 (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.rs | 2 | ||||
| -rw-r--r-- | embassy-sync/src/pubsub/publisher.rs | 6 | ||||
| -rw-r--r-- | embassy-sync/src/pubsub/subscriber.rs | 3 |
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)] | ||
| 74 | pub struct PubSubChannel<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> { | 75 | pub 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)] | ||
| 300 | struct PubSubState<T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> { | 302 | struct 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}; | |||
| 10 | use crate::blocking_mutex::raw::RawMutex; | 10 | use crate::blocking_mutex::raw::RawMutex; |
| 11 | 11 | ||
| 12 | /// A publisher to a channel | 12 | /// A publisher to a channel |
| 13 | #[derive(Debug)] | ||
| 13 | pub struct Pub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { | 14 | pub 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)] | ||
| 109 | pub struct Publisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( | 111 | pub 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)] | ||
| 133 | pub struct ImmediatePub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { | 136 | pub 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)] | ||
| 208 | pub struct ImmediatePublisher<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( | 212 | pub 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)] | ||
| 232 | pub struct PubSink<'a, 'p, PSB, T> | 237 | pub struct PubSink<'a, 'p, PSB, T> |
| 233 | where | 238 | where |
| 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)] | ||
| 293 | pub struct PublisherWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { | 299 | pub 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}; | |||
| 10 | use crate::blocking_mutex::raw::RawMutex; | 10 | use crate::blocking_mutex::raw::RawMutex; |
| 11 | 11 | ||
| 12 | /// A subscriber to a channel | 12 | /// A subscriber to a channel |
| 13 | #[derive(Debug)] | ||
| 13 | pub struct Sub<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { | 14 | pub 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)] | ||
| 154 | pub struct Subscriber<'a, M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize>( | 156 | pub 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)] | ||
| 178 | pub struct SubscriberWaitFuture<'s, 'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> { | 181 | pub 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 | } |
