diff options
| -rw-r--r-- | embassy-sync/CHANGELOG.md | 2 | ||||
| -rw-r--r-- | embassy-sync/src/channel.rs | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/embassy-sync/CHANGELOG.md b/embassy-sync/CHANGELOG.md index 3f6b39d8b..46466d610 100644 --- a/embassy-sync/CHANGELOG.md +++ b/embassy-sync/CHANGELOG.md | |||
| @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 7 | 7 | ||
| 8 | ## Unreleased | 8 | ## Unreleased |
| 9 | 9 | ||
| 10 | - Add `len`, `is_empty` and `is_full` functions to `Channel`. | 10 | - Add `capacity`, `free_capacity`, `len`, `is_empty` and `is_full` functions to `Channel`. |
| 11 | 11 | ||
| 12 | ## 0.5.0 - 2023-12-04 | 12 | ## 0.5.0 - 2023-12-04 |
| 13 | 13 | ||
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()) |
