aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/pubsub/subscriber.rs
diff options
context:
space:
mode:
authorDion Dokter <[email protected]>2024-05-20 15:34:03 +0200
committerDion Dokter <[email protected]>2024-05-20 15:34:03 +0200
commita76082b104edd4cbb7f10a4a589ef6773d8d6e4f (patch)
treed91061e9bf142f0b51713f90ec52936ed0837d8f /embassy-sync/src/pubsub/subscriber.rs
parent2a4a714060d4cdb976eab62a70f9c1242425714f (diff)
Expose new length functions in the subs and pubs
Diffstat (limited to 'embassy-sync/src/pubsub/subscriber.rs')
-rw-r--r--embassy-sync/src/pubsub/subscriber.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/embassy-sync/src/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs
index f420a75f0..2e2bd26a9 100644
--- a/embassy-sync/src/pubsub/subscriber.rs
+++ b/embassy-sync/src/pubsub/subscriber.rs
@@ -65,10 +65,39 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Sub<'a, PSB, T> {
65 } 65 }
66 } 66 }
67 67
68 /// The amount of messages this subscriber hasn't received yet 68 /// The amount of messages this subscriber hasn't received yet. This is like [Self::len] but specifically
69 /// for this subscriber.
69 pub fn available(&self) -> u64 { 70 pub fn available(&self) -> u64 {
70 self.channel.available(self.next_message_id) 71 self.channel.available(self.next_message_id)
71 } 72 }
73
74 /// Returns the maximum number of elements the ***channel*** can hold.
75 pub fn capacity(&self) -> usize {
76 self.channel.capacity()
77 }
78
79 /// Returns the free capacity of the ***channel***.
80 ///
81 /// This is equivalent to `capacity() - len()`
82 pub fn free_capacity(&self) -> usize {
83 self.channel.free_capacity()
84 }
85
86 /// Returns the number of elements currently in the ***channel***.
87 /// See [Self::available] for how many messages are available for this subscriber.
88 pub fn len(&self) -> usize {
89 self.channel.len()
90 }
91
92 /// Returns whether the ***channel*** is empty.
93 pub fn is_empty(&self) -> bool {
94 self.channel.is_empty()
95 }
96
97 /// Returns whether the ***channel*** is full.
98 pub fn is_full(&self) -> bool {
99 self.channel.is_full()
100 }
72} 101}
73 102
74impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Drop for Sub<'a, PSB, T> { 103impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Drop for Sub<'a, PSB, T> {