diff options
| author | Oliver Rockstedt <[email protected]> | 2024-05-18 13:37:51 +0200 |
|---|---|---|
| committer | Oliver Rockstedt <[email protected]> | 2024-05-18 13:37:51 +0200 |
| commit | 3d9b502c7af1f1dab92ee4a3aa07dc667a3bf103 (patch) | |
| tree | d16b83448b34e9968c1017a133844bce502f3034 /embassy-sync/src | |
| parent | fa94b5cec0ea257a5619db361081c340cefe6af6 (diff) | |
embassy-sync: Add capacity and free_capacity functions to Channel
Diffstat (limited to 'embassy-sync/src')
| -rw-r--r-- | embassy-sync/src/channel.rs | 12 |
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()) |
