ogg: Add a consuming iterator over all items

This commit is contained in:
Uwe Klotz 2023-01-15 10:34:37 +01:00 committed by Alex
parent 751f5ca06f
commit 07606159ec

View file

@ -61,11 +61,21 @@ impl VorbisComments {
self.vendor = vendor
}
/// Returns an [`Iterator`] over the stored key/value pairs
pub fn items(&self) -> impl Iterator<Item = (&str, &str)> + Clone {
/// Visit all items
///
/// Returns an [`Iterator`] over the stored key/value pairs.
pub fn items(&self) -> impl ExactSizeIterator<Item = (&str, &str)> + Clone {
self.items.iter().map(|(k, v)| (k.as_str(), v.as_str()))
}
/// Consume all items
///
/// Returns an [`Iterator`] with the stored key/value pairs.
pub fn take_items(&mut self) -> impl ExactSizeIterator<Item = (String, String)> {
let items = std::mem::take(&mut self.items);
items.into_iter()
}
/// Gets an item by key
///
/// NOTE: This is case-sensitive