Skip to content

Commit

Permalink
Add capacity, free_capacity, clear, len, is_empty and is_full functio…
Browse files Browse the repository at this point in the history
…ns to priority_channel::{Sender, Receiver}
  • Loading branch information
sourcebox committed Oct 7, 2024
1 parent 0774813 commit 2704ac3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions embassy-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add LazyLock sync primitive.
- Add `clear`, `len`, `is_empty` and `is_full` functions to `zerocopy_channel`.
- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `channel::{Sender, Receiver}`.
- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `priority_channel::{Sender, Receiver}`.

## 0.6.0 - 2024-05-29

Expand Down
84 changes: 84 additions & 0 deletions embassy-sync/src/priority_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ where
pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
self.channel.poll_ready_to_send(cx)
}

/// Returns the maximum number of elements the channel can hold.
///
/// See [`PriorityChannel::capacity()`]
pub const fn capacity(&self) -> usize {
self.channel.capacity()
}

/// Returns the free capacity of the channel.
///
/// See [`PriorityChannel::free_capacity()`]
pub fn free_capacity(&self) -> usize {
self.channel.free_capacity()
}

/// Clears all elements in the channel.
///
/// See [`PriorityChannel::clear()`]
pub fn clear(&self) {
self.channel.clear();
}

/// Returns the number of elements currently in the channel.
///
/// See [`PriorityChannel::len()`]
pub fn len(&self) -> usize {
self.channel.len()
}

/// Returns whether the channel is empty.
///
/// See [`PriorityChannel::is_empty()`]
pub fn is_empty(&self) -> bool {
self.channel.is_empty()
}

/// Returns whether the channel is full.
///
/// See [`PriorityChannel::is_full()`]
pub fn is_full(&self) -> bool {
self.channel.is_full()
}
}

impl<'ch, M, T, K, const N: usize> From<Sender<'ch, M, T, K, N>> for DynamicSender<'ch, T>
Expand Down Expand Up @@ -146,6 +188,48 @@ where
pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> {
self.channel.poll_receive(cx)
}

/// Returns the maximum number of elements the channel can hold.
///
/// See [`PriorityChannel::capacity()`]
pub const fn capacity(&self) -> usize {
self.channel.capacity()
}

/// Returns the free capacity of the channel.
///
/// See [`PriorityChannel::free_capacity()`]
pub fn free_capacity(&self) -> usize {
self.channel.free_capacity()
}

/// Clears all elements in the channel.
///
/// See [`PriorityChannel::clear()`]
pub fn clear(&self) {
self.channel.clear();
}

/// Returns the number of elements currently in the channel.
///
/// See [`PriorityChannel::len()`]
pub fn len(&self) -> usize {
self.channel.len()
}

/// Returns whether the channel is empty.
///
/// See [`PriorityChannel::is_empty()`]
pub fn is_empty(&self) -> bool {
self.channel.is_empty()
}

/// Returns whether the channel is full.
///
/// See [`PriorityChannel::is_full()`]
pub fn is_full(&self) -> bool {
self.channel.is_full()
}
}

impl<'ch, M, T, K, const N: usize> From<Receiver<'ch, M, T, K, N>> for DynamicReceiver<'ch, T>
Expand Down

0 comments on commit 2704ac3

Please sign in to comment.