aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/channel.rs
diff options
context:
space:
mode:
authorOliver Rockstedt <[email protected]>2024-05-18 13:37:51 +0200
committerOliver Rockstedt <[email protected]>2024-05-18 13:37:51 +0200
commit3d9b502c7af1f1dab92ee4a3aa07dc667a3bf103 (patch)
treed16b83448b34e9968c1017a133844bce502f3034 /embassy-sync/src/channel.rs
parentfa94b5cec0ea257a5619db361081c340cefe6af6 (diff)
embassy-sync: Add capacity and free_capacity functions to Channel
Diffstat (limited to 'embassy-sync/src/channel.rs')
-rw-r--r--embassy-sync/src/channel.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index c4267064c..f9f71d026 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -620,6 +620,18 @@ where
620 self.lock(|c| c.try_receive()) 620 self.lock(|c| c.try_receive())
621 } 621 }
622 622
623 /// Returns the maximum number of elements the channel can hold.
624 pub const fn capacity(&self) -> usize {
625 N
626 }
627
628 /// Returns the free capacity of the channel.
629 ///
630 /// This is equivalent to `capacity() - len()`
631 pub fn free_capacity(&self) -> usize {
632 N - self.len()
633 }
634
623 /// Returns the number of elements currently in the channel. 635 /// Returns the number of elements currently in the channel.
624 pub fn len(&self) -> usize { 636 pub fn len(&self) -> usize {
625 self.lock(|c| c.len()) 637 self.lock(|c| c.len())