aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
authorOliver Rockstedt <[email protected]>2024-10-07 13:30:46 +0200
committerOliver Rockstedt <[email protected]>2024-10-07 13:30:46 +0200
commitbaef775f6b33b4fd45dd3a4bb1122a52c6d22c67 (patch)
treeed5dd924baa9dceb0d4bd78eea664b55c8147daf /embassy-sync
parentaa2f6ae965a2b0717aaf3530a87036e6efd3181e (diff)
Add capacity, free_capacity, clear, len, is_empty and is_full functions to Channel::{Sender, Receiver}
Diffstat (limited to 'embassy-sync')
-rw-r--r--embassy-sync/CHANGELOG.md1
-rw-r--r--embassy-sync/src/channel.rs84
2 files changed, 85 insertions, 0 deletions
diff --git a/embassy-sync/CHANGELOG.md b/embassy-sync/CHANGELOG.md
index 8847e7e88..253a6cc82 100644
--- a/embassy-sync/CHANGELOG.md
+++ b/embassy-sync/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9 9
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 13
13## 0.6.0 - 2024-05-29 14## 0.6.0 - 2024-05-29
14 15
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 55ac5fb66..18b053111 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -72,6 +72,48 @@ where
72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { 72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
73 self.channel.poll_ready_to_send(cx) 73 self.channel.poll_ready_to_send(cx)
74 } 74 }
75
76 /// Returns the maximum number of elements the channel can hold.
77 ///
78 /// See [`Channel::capacity()`]
79 pub const fn capacity(&self) -> usize {
80 self.channel.capacity()
81 }
82
83 /// Returns the free capacity of the channel.
84 ///
85 /// See [`Channel::free_capacity()`]
86 pub fn free_capacity(&self) -> usize {
87 self.channel.free_capacity()
88 }
89
90 /// Clears all elements in the channel.
91 ///
92 /// See [`Channel::clear()`]
93 pub fn clear(&self) {
94 self.channel.clear();
95 }
96
97 /// Returns the number of elements currently in the channel.
98 ///
99 /// See [`Channel::len()`]
100 pub fn len(&self) -> usize {
101 self.channel.len()
102 }
103
104 /// Returns whether the channel is empty.
105 ///
106 /// See [`Channel::is_empty()`]
107 pub fn is_empty(&self) -> bool {
108 self.channel.is_empty()
109 }
110
111 /// Returns whether the channel is full.
112 ///
113 /// See [`Channel::is_full()`]
114 pub fn is_full(&self) -> bool {
115 self.channel.is_full()
116 }
75} 117}
76 118
77/// Send-only access to a [`Channel`] without knowing channel size. 119/// Send-only access to a [`Channel`] without knowing channel size.
@@ -179,6 +221,48 @@ where
179 pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> { 221 pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> {
180 self.channel.poll_receive(cx) 222 self.channel.poll_receive(cx)
181 } 223 }
224
225 /// Returns the maximum number of elements the channel can hold.
226 ///
227 /// See [`Channel::capacity()`]
228 pub const fn capacity(&self) -> usize {
229 self.channel.capacity()
230 }
231
232 /// Returns the free capacity of the channel.
233 ///
234 /// See [`Channel::free_capacity()`]
235 pub fn free_capacity(&self) -> usize {
236 self.channel.free_capacity()
237 }
238
239 /// Clears all elements in the channel.
240 ///
241 /// See [`Channel::clear()`]
242 pub fn clear(&self) {
243 self.channel.clear();
244 }
245
246 /// Returns the number of elements currently in the channel.
247 ///
248 /// See [`Channel::len()`]
249 pub fn len(&self) -> usize {
250 self.channel.len()
251 }
252
253 /// Returns whether the channel is empty.
254 ///
255 /// See [`Channel::is_empty()`]
256 pub fn is_empty(&self) -> bool {
257 self.channel.is_empty()
258 }
259
260 /// Returns whether the channel is full.
261 ///
262 /// See [`Channel::is_full()`]
263 pub fn is_full(&self) -> bool {
264 self.channel.is_full()
265 }
182} 266}
183 267
184/// Receive-only access to a [`Channel`] without knowing channel size. 268/// Receive-only access to a [`Channel`] without knowing channel size.