From 54881dfa157ceff3ed66368a1cb268fb09f06079 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Mar 2022 01:12:28 +0100 Subject: [PATCH] Add a len() function to Buffer --- src/buffer.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/buffer.rs b/src/buffer.rs index 49fbdeab..2d9dc00c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -236,6 +236,15 @@ impl ExactSizeIterator for BlocksIter<'_, '_> {} impl ExactSizeIterator for BlockChannelsIter<'_, '_> {} impl<'a> Buffer<'a> { + /// Return the numer of samples in this buffer. + pub fn len(&self) -> usize { + if self.output_slices.is_empty() { + 0 + } else { + self.output_slices[0].len() + } + } + /// Returns true if this buffer does not contain any samples. pub fn is_empty(&self) -> bool { self.output_slices.is_empty() || self.output_slices[0].is_empty()