From 12d725508c087082cdefd58202256625eebf82c6 Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 23 Feb 2026 19:09:09 +0100 Subject: [PATCH] Add accessor methods for Storage trait impls --- bbqueue/Cargo.toml | 2 +- bbqueue/src/queue.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bbqueue/Cargo.toml b/bbqueue/Cargo.toml index ac88e9c..8e655fe 100644 --- a/bbqueue/Cargo.toml +++ b/bbqueue/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bbqueue" -version = "0.6.1" +version = "0.6.2" 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/queue.rs b/bbqueue/src/queue.rs index 2228e6d..6f0eb14 100644 --- a/bbqueue/src/queue.rs +++ b/bbqueue/src/queue.rs @@ -97,12 +97,28 @@ impl BBQueue { } /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + #[inline(always)] pub fn capacity(&self) -> usize { // SAFETY: capacity never changes, therefore reading the len is safe unsafe { self.sto.ptr_len().1 } } + + /// Get access to the internal storage implementation details + /// + /// NOTE: Although this method is safe, use of the `Storage` methods are not. + /// You should *never* attempt to access or modify the underlying data contained + /// in a storage implementation while the bbqueue is live. That will IMMEDIATELY + /// lead to undefined behavior. + /// + /// As far as I am aware, the only reasonable use for this is for cases where you + /// have a custom `Storage` implementation that has unique teardown/drop in place + /// requirements. Treat any uses of this function with *extreme* caution! + #[inline(always)] + pub fn storage(&self) -> &S { + &self.sto + } } #[cfg(feature = "alloc")] @@ -148,6 +164,30 @@ impl crate::queue::ArcBBQueue { bbq: self.0.bbq_ref(), } } + + /// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`] + #[inline(always)] + pub fn capacity(&self) -> usize { + // SAFETY: capacity never changes, therefore reading the len is safe + unsafe { + self.0.sto.ptr_len().1 + } + } + + /// Get access to the internal storage implementation details + /// + /// NOTE: Although this method is safe, use of the `Storage` methods are not. + /// You should *never* attempt to access or modify the underlying data contained + /// in a storage implementation while the bbqueue is live. That will IMMEDIATELY + /// lead to undefined behavior. + /// + /// As far as I am aware, the only reasonable use for this is for cases where you + /// have a custom `Storage` implementation that has unique teardown/drop in place + /// requirements. Treat any uses of this function with *extreme* caution! + #[inline(always)] + pub fn storage(&self) -> &S { + &self.0.sto + } } #[cfg(test)]