From 3d9b502c7af1f1dab92ee4a3aa07dc667a3bf103 Mon Sep 17 00:00:00 2001 From: Oliver Rockstedt Date: Sat, 18 May 2024 13:37:51 +0200 Subject: embassy-sync: Add capacity and free_capacity functions to Channel --- embassy-sync/src/channel.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'embassy-sync/src') 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 self.lock(|c| c.try_receive()) } + /// Returns the maximum number of elements the channel can hold. + pub const fn capacity(&self) -> usize { + N + } + + /// Returns the free capacity of the channel. + /// + /// This is equivalent to `capacity() - len()` + pub fn free_capacity(&self) -> usize { + N - self.len() + } + /// Returns the number of elements currently in the channel. pub fn len(&self) -> usize { self.lock(|c| c.len()) -- cgit