From 5c572106b300aae94ca35cbab33866a31ea516e4 Mon Sep 17 00:00:00 2001 From: James Munns Date: Fri, 20 Feb 2026 17:53:50 +0100 Subject: [PATCH] Add "capacity" accessor --- bbqueue/Cargo.toml | 2 +- bbqueue/src/prod_cons/framed.rs | 10 ++++++++++ bbqueue/src/prod_cons/stream.rs | 10 ++++++++++ bbqueue/src/queue.rs | 8 ++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bbqueue/Cargo.toml b/bbqueue/Cargo.toml index 0b22f57..ac88e9c 100644 --- a/bbqueue/Cargo.toml +++ b/bbqueue/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bbqueue" -version = "0.6.0" +version = "0.6.1" description = "A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers" repository = "https://github.com/jamesmunns/bbqueue" authors = ["James Munns "] diff --git a/bbqueue/src/prod_cons/framed.rs b/bbqueue/src/prod_cons/framed.rs index 268de80..9418e16 100644 --- a/bbqueue/src/prod_cons/framed.rs +++ b/bbqueue/src/prod_cons/framed.rs @@ -147,6 +147,11 @@ where hdr: sz, }) } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + pub fn capacity(&self) -> usize { + self.bbq.capacity() + } } impl FramedProducer @@ -222,6 +227,11 @@ where hdr, }) } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + pub fn capacity(&self) -> usize { + self.bbq.capacity() + } } impl FramedConsumer diff --git a/bbqueue/src/prod_cons/stream.rs b/bbqueue/src/prod_cons/stream.rs index bfcd7b9..543afbf 100644 --- a/bbqueue/src/prod_cons/stream.rs +++ b/bbqueue/src/prod_cons/stream.rs @@ -120,6 +120,11 @@ where to_commit: 0, }) } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + pub fn capacity(&self) -> usize { + self.bbq.capacity() + } } impl StreamProducer @@ -174,6 +179,11 @@ where to_release: 0, }) } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + pub fn capacity(&self) -> usize { + self.bbq.capacity() + } } impl StreamConsumer diff --git a/bbqueue/src/queue.rs b/bbqueue/src/queue.rs index b24feba..2228e6d 100644 --- a/bbqueue/src/queue.rs +++ b/bbqueue/src/queue.rs @@ -95,6 +95,14 @@ impl BBQueue { pub const fn stream_consumer(&self) -> StreamConsumer<&'_ Self> { StreamConsumer { bbq: self } } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + pub fn capacity(&self) -> usize { + // SAFETY: capacity never changes, therefore reading the len is safe + unsafe { + self.sto.ptr_len().1 + } + } } #[cfg(feature = "alloc")]