From 76fca86d1ca0bad691016f6b290091e9790c5189 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 17 Jan 2023 07:20:47 -0500 Subject: [PATCH] ogg_pager: Add `Packets::{len, is_empty}` --- ogg_pager/src/packets.rs | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ogg_pager/src/packets.rs b/ogg_pager/src/packets.rs index 79f48c92..b56c9bd2 100644 --- a/ogg_pager/src/packets.rs +++ b/ogg_pager/src/packets.rs @@ -158,6 +158,49 @@ impl Packets { byte_count_to_read } + /// Returns the number of packets + /// + /// # Examples + /// + /// ```rust + /// use ogg_pager::Packets; + /// + /// # fn main() -> Result<(), ogg_pager::PageError> { + /// # let path = "../tests/files/assets/minimal/full_test.ogg"; + /// let mut file = std::fs::File::open(path)?; + /// + /// // I want to read 2 packets + /// let packets = Packets::read_count(&mut file, 2)?; + /// + /// // And that's what I received! + /// assert_eq!(packets.len(), 2); + /// # Ok(()) } + /// ``` + pub fn len(&self) -> usize { + self.packet_sizes.len() + } + + /// Returns true if there are no packets + /// + /// # Examples + /// + /// ```rust + /// use ogg_pager::Packets; + /// + /// # fn main() -> Result<(), ogg_pager::PageError> { + /// # let path = "../tests/files/assets/minimal/full_test.ogg"; + /// let mut file = std::fs::File::open(path)?; + /// + /// let packets = Packets::read(&mut file)?; + /// + /// // My file contains packets! + /// assert_eq!(!packets.is_empty()); + /// # Ok(()) } + /// ``` + pub fn is_empty(&self) -> bool { + self.packet_sizes.is_empty() + } + /// Gets the packet at a specified index, returning its contents /// /// NOTES: