Merge pull request #3400 from sourcebox/sync-additions

Add capacity, free_capacity, clear, len, is_empty and is_full functions to Channel::{Sender, Receiver}
This commit is contained in:
Dario Nieuwenhuis 2024-10-07 12:26:05 +00:00 committed by GitHub
commit 7920ba8f8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 85 additions and 0 deletions

View File

@ -9,6 +9,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}`.
## 0.6.0 - 2024-05-29

View File

@ -72,6 +72,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 [`Channel::capacity()`]
pub const fn capacity(&self) -> usize {
self.channel.capacity()
}
/// Returns the free capacity of the channel.
///
/// See [`Channel::free_capacity()`]
pub fn free_capacity(&self) -> usize {
self.channel.free_capacity()
}
/// Clears all elements in the channel.
///
/// See [`Channel::clear()`]
pub fn clear(&self) {
self.channel.clear();
}
/// Returns the number of elements currently in the channel.
///
/// See [`Channel::len()`]
pub fn len(&self) -> usize {
self.channel.len()
}
/// Returns whether the channel is empty.
///
/// See [`Channel::is_empty()`]
pub fn is_empty(&self) -> bool {
self.channel.is_empty()
}
/// Returns whether the channel is full.
///
/// See [`Channel::is_full()`]
pub fn is_full(&self) -> bool {
self.channel.is_full()
}
}
/// Send-only access to a [`Channel`] without knowing channel size.
@ -179,6 +221,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 [`Channel::capacity()`]
pub const fn capacity(&self) -> usize {
self.channel.capacity()
}
/// Returns the free capacity of the channel.
///
/// See [`Channel::free_capacity()`]
pub fn free_capacity(&self) -> usize {
self.channel.free_capacity()
}
/// Clears all elements in the channel.
///
/// See [`Channel::clear()`]
pub fn clear(&self) {
self.channel.clear();
}
/// Returns the number of elements currently in the channel.
///
/// See [`Channel::len()`]
pub fn len(&self) -> usize {
self.channel.len()
}
/// Returns whether the channel is empty.
///
/// See [`Channel::is_empty()`]
pub fn is_empty(&self) -> bool {
self.channel.is_empty()
}
/// Returns whether the channel is full.
///
/// See [`Channel::is_full()`]
pub fn is_full(&self) -> bool {
self.channel.is_full()
}
}
/// Receive-only access to a [`Channel`] without knowing channel size.