gstreamer: Implement FromIterator<Caps> and Extend<Caps> for Caps

This allows easily generating new/extending existing caps from an
iterator.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1151>
This commit is contained in:
Sebastian Dröge 2022-11-21 10:10:04 +02:00
parent 774fafd987
commit 56b9b66027

View file

@ -204,6 +204,21 @@ impl std::iter::FromIterator<(Structure, Option<CapsFeatures>)> for Caps {
} }
} }
impl std::iter::FromIterator<Caps> for Caps {
fn from_iter<T: IntoIterator<Item = Caps>>(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<Structure> for CapsRef { impl std::iter::Extend<Structure> for CapsRef {
fn extend<T: IntoIterator<Item = Structure>>(&mut self, iter: T) { fn extend<T: IntoIterator<Item = Structure>>(&mut self, iter: T) {
iter.into_iter().for_each(|s| self.append_structure(s)); iter.into_iter().for_each(|s| self.append_structure(s));
@ -224,6 +239,12 @@ impl std::iter::Extend<(Structure, Option<CapsFeatures>)> for CapsRef {
} }
} }
impl std::iter::Extend<Caps> for CapsRef {
fn extend<T: IntoIterator<Item = Caps>>(&mut self, iter: T) {
iter.into_iter().for_each(|caps| self.append(caps));
}
}
impl CapsRef { impl CapsRef {
#[doc(alias = "gst_caps_set_simple")] #[doc(alias = "gst_caps_set_simple")]
pub fn set_simple(&mut self, values: &[(&str, &(dyn ToSendValue + Sync))]) { pub fn set_simple(&mut self, values: &[(&str, &(dyn ToSendValue + Sync))]) {