From 56b9b66027dbf245c47895519682631c1b00c747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 21 Nov 2022 10:10:04 +0200 Subject: [PATCH] gstreamer: Implement `FromIterator` and `Extend` for `Caps` This allows easily generating new/extending existing caps from an iterator. Part-of: --- gstreamer/src/caps.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 6606d8c97..0eef0c216 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -204,6 +204,21 @@ impl std::iter::FromIterator<(Structure, Option)> for Caps { } } +impl std::iter::FromIterator for Caps { + fn from_iter>(iter: T) -> Self { + assert_initialized_main_thread!(); + let mut caps = Caps::new_empty(); + + { + let caps = caps.get_mut().unwrap(); + iter.into_iter() + .for_each(|other_caps| caps.append(other_caps)); + } + + caps + } +} + impl std::iter::Extend for CapsRef { fn extend>(&mut self, iter: T) { iter.into_iter().for_each(|s| self.append_structure(s)); @@ -224,6 +239,12 @@ impl std::iter::Extend<(Structure, Option)> for CapsRef { } } +impl std::iter::Extend for CapsRef { + fn extend>(&mut self, iter: T) { + iter.into_iter().for_each(|caps| self.append(caps)); + } +} + impl CapsRef { #[doc(alias = "gst_caps_set_simple")] pub fn set_simple(&mut self, values: &[(&str, &(dyn ToSendValue + Sync))]) {