diff options
| author | Oliver Rockstedt <[email protected]> | 2024-10-07 17:35:11 +0200 |
|---|---|---|
| committer | Oliver Rockstedt <[email protected]> | 2024-10-07 17:35:11 +0200 |
| commit | 2704ac3d289650173b60e1a29d70e8903bea4cf1 (patch) | |
| tree | a0e24a8a1517584555213f688afe39f05f9795fe /embassy-sync | |
| parent | 07748131dde887d214c1d9373ec642907d547dcd (diff) | |
Add capacity, free_capacity, clear, len, is_empty and is_full functions to priority_channel::{Sender, Receiver}
Diffstat (limited to 'embassy-sync')
| -rw-r--r-- | embassy-sync/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-sync/src/priority_channel.rs | 84 |
2 files changed, 85 insertions, 0 deletions
diff --git a/embassy-sync/CHANGELOG.md b/embassy-sync/CHANGELOG.md index 83fd666ac..1668c9319 100644 --- a/embassy-sync/CHANGELOG.md +++ b/embassy-sync/CHANGELOG.md | |||
| @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 10 | - Add LazyLock sync primitive. | 10 | - Add LazyLock sync primitive. |
| 11 | - Add `clear`, `len`, `is_empty` and `is_full` functions to `zerocopy_channel`. | 11 | - Add `clear`, `len`, `is_empty` and `is_full` functions to `zerocopy_channel`. |
| 12 | - Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `channel::{Sender, Receiver}`. | 12 | - Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `channel::{Sender, Receiver}`. |
| 13 | - Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `priority_channel::{Sender, Receiver}`. | ||
| 13 | 14 | ||
| 14 | ## 0.6.0 - 2024-05-29 | 15 | ## 0.6.0 - 2024-05-29 |
| 15 | 16 | ||
diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs index 24c6c5a7f..1f4d8667c 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/priority_channel.rs | |||
| @@ -71,6 +71,48 @@ where | |||
| 71 | pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { | 71 | pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { |
| 72 | self.channel.poll_ready_to_send(cx) | 72 | self.channel.poll_ready_to_send(cx) |
| 73 | } | 73 | } |
| 74 | |||
| 75 | /// Returns the maximum number of elements the channel can hold. | ||
| 76 | /// | ||
| 77 | /// See [`PriorityChannel::capacity()`] | ||
| 78 | pub const fn capacity(&self) -> usize { | ||
| 79 | self.channel.capacity() | ||
| 80 | } | ||
| 81 | |||
| 82 | /// Returns the free capacity of the channel. | ||
| 83 | /// | ||
| 84 | /// See [`PriorityChannel::free_capacity()`] | ||
| 85 | pub fn free_capacity(&self) -> usize { | ||
| 86 | self.channel.free_capacity() | ||
| 87 | } | ||
| 88 | |||
| 89 | /// Clears all elements in the channel. | ||
| 90 | /// | ||
| 91 | /// See [`PriorityChannel::clear()`] | ||
| 92 | pub fn clear(&self) { | ||
| 93 | self.channel.clear(); | ||
| 94 | } | ||
| 95 | |||
| 96 | /// Returns the number of elements currently in the channel. | ||
| 97 | /// | ||
| 98 | /// See [`PriorityChannel::len()`] | ||
| 99 | pub fn len(&self) -> usize { | ||
| 100 | self.channel.len() | ||
| 101 | } | ||
| 102 | |||
| 103 | /// Returns whether the channel is empty. | ||
| 104 | /// | ||
| 105 | /// See [`PriorityChannel::is_empty()`] | ||
| 106 | pub fn is_empty(&self) -> bool { | ||
| 107 | self.channel.is_empty() | ||
| 108 | } | ||
| 109 | |||
| 110 | /// Returns whether the channel is full. | ||
| 111 | /// | ||
| 112 | /// See [`PriorityChannel::is_full()`] | ||
| 113 | pub fn is_full(&self) -> bool { | ||
| 114 | self.channel.is_full() | ||
| 115 | } | ||
| 74 | } | 116 | } |
| 75 | 117 | ||
| 76 | impl<'ch, M, T, K, const N: usize> From<Sender<'ch, M, T, K, N>> for DynamicSender<'ch, T> | 118 | impl<'ch, M, T, K, const N: usize> From<Sender<'ch, M, T, K, N>> for DynamicSender<'ch, T> |
| @@ -146,6 +188,48 @@ where | |||
| 146 | pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> { | 188 | pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> { |
| 147 | self.channel.poll_receive(cx) | 189 | self.channel.poll_receive(cx) |
| 148 | } | 190 | } |
| 191 | |||
| 192 | /// Returns the maximum number of elements the channel can hold. | ||
| 193 | /// | ||
| 194 | /// See [`PriorityChannel::capacity()`] | ||
| 195 | pub const fn capacity(&self) -> usize { | ||
| 196 | self.channel.capacity() | ||
| 197 | } | ||
| 198 | |||
| 199 | /// Returns the free capacity of the channel. | ||
| 200 | /// | ||
| 201 | /// See [`PriorityChannel::free_capacity()`] | ||
| 202 | pub fn free_capacity(&self) -> usize { | ||
| 203 | self.channel.free_capacity() | ||
| 204 | } | ||
| 205 | |||
| 206 | /// Clears all elements in the channel. | ||
| 207 | /// | ||
| 208 | /// See [`PriorityChannel::clear()`] | ||
| 209 | pub fn clear(&self) { | ||
| 210 | self.channel.clear(); | ||
| 211 | } | ||
| 212 | |||
| 213 | /// Returns the number of elements currently in the channel. | ||
| 214 | /// | ||
| 215 | /// See [`PriorityChannel::len()`] | ||
| 216 | pub fn len(&self) -> usize { | ||
| 217 | self.channel.len() | ||
| 218 | } | ||
| 219 | |||
| 220 | /// Returns whether the channel is empty. | ||
| 221 | /// | ||
| 222 | /// See [`PriorityChannel::is_empty()`] | ||
| 223 | pub fn is_empty(&self) -> bool { | ||
| 224 | self.channel.is_empty() | ||
| 225 | } | ||
| 226 | |||
| 227 | /// Returns whether the channel is full. | ||
| 228 | /// | ||
| 229 | /// See [`PriorityChannel::is_full()`] | ||
| 230 | pub fn is_full(&self) -> bool { | ||
| 231 | self.channel.is_full() | ||
| 232 | } | ||
| 149 | } | 233 | } |
| 150 | 234 | ||
| 151 | impl<'ch, M, T, K, const N: usize> From<Receiver<'ch, M, T, K, N>> for DynamicReceiver<'ch, T> | 235 | impl<'ch, M, T, K, const N: usize> From<Receiver<'ch, M, T, K, N>> for DynamicReceiver<'ch, T> |
