mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 17:41:05 +00:00
gstreamer: Implement Extend trait for buffer, buffer list, caps, caps features and structure
And also implement FromIterator<Memory> for buffer.
This commit is contained in:
parent
febd0ee144
commit
a7be9ea9d9
5 changed files with 76 additions and 0 deletions
|
@ -912,6 +912,29 @@ impl<'a> IntoIterator for &'a BufferRef {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::iter::FromIterator<Memory> for Buffer {
|
||||
fn from_iter<T: IntoIterator<Item = Memory>>(iter: T) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
let iter = iter.into_iter();
|
||||
|
||||
let mut buffer = Buffer::new();
|
||||
|
||||
{
|
||||
let buffer = buffer.get_mut().unwrap();
|
||||
iter.for_each(|m| buffer.append_memory(m));
|
||||
}
|
||||
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Extend<Memory> for BufferRef {
|
||||
fn extend<T: IntoIterator<Item = Memory>>(&mut self, iter: T) {
|
||||
iter.into_iter().for_each(|m| self.append_memory(m));
|
||||
}
|
||||
}
|
||||
|
||||
define_iter!(
|
||||
IterOwned,
|
||||
&'a BufferRef,
|
||||
|
|
|
@ -298,6 +298,12 @@ impl std::iter::FromIterator<Buffer> for BufferList {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::iter::Extend<Buffer> for BufferListRef {
|
||||
fn extend<T: IntoIterator<Item = Buffer>>(&mut self, iter: T) {
|
||||
iter.into_iter().for_each(|b| self.add(b));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -173,6 +173,41 @@ impl std::iter::FromIterator<(Structure, CapsFeatures)> for Caps {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::iter::FromIterator<(Structure, Option<CapsFeatures>)> for Caps {
|
||||
fn from_iter<T: IntoIterator<Item = (Structure, Option<CapsFeatures>)>>(iter: T) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
let mut caps = Caps::new_empty();
|
||||
|
||||
{
|
||||
let caps = caps.get_mut().unwrap();
|
||||
iter.into_iter()
|
||||
.for_each(|(s, f)| caps.append_structure_full(s, f));
|
||||
}
|
||||
|
||||
caps
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Extend<Structure> for CapsRef {
|
||||
fn extend<T: IntoIterator<Item = Structure>>(&mut self, iter: T) {
|
||||
iter.into_iter().for_each(|s| self.append_structure(s));
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Extend<(Structure, CapsFeatures)> for CapsRef {
|
||||
fn extend<T: IntoIterator<Item = (Structure, CapsFeatures)>>(&mut self, iter: T) {
|
||||
iter.into_iter()
|
||||
.for_each(|(s, f)| self.append_structure_full(s, Some(f)));
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Extend<(Structure, Option<CapsFeatures>)> for CapsRef {
|
||||
fn extend<T: IntoIterator<Item = (Structure, Option<CapsFeatures>)>>(&mut self, iter: T) {
|
||||
iter.into_iter()
|
||||
.for_each(|(s, f)| self.append_structure_full(s, f));
|
||||
}
|
||||
}
|
||||
|
||||
impl CapsRef {
|
||||
pub fn set_simple(&mut self, values: &[(&str, &(dyn ToSendValue + Sync))]) {
|
||||
for &(name, value) in values {
|
||||
|
|
|
@ -407,6 +407,12 @@ impl glib::types::StaticType for CapsFeaturesRef {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> std::iter::Extend<&'a str> for CapsFeaturesRef {
|
||||
fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T) {
|
||||
iter.into_iter().for_each(|f| self.add(f));
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a> glib::value::FromValue<'a> for &'a CapsFeaturesRef {
|
||||
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
|
||||
|
||||
|
|
|
@ -844,6 +844,12 @@ impl<'a> IntoIterator for &'a StructureRef {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> std::iter::Extend<(&'a str, SendValue)> for StructureRef {
|
||||
fn extend<T: IntoIterator<Item = (&'a str, SendValue)>>(&mut self, iter: T) {
|
||||
iter.into_iter().for_each(|(f, v)| self.set_value(f, v));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Builder {
|
||||
s: Structure,
|
||||
|
|
Loading…
Reference in a new issue