From d1cf7d609fef337985f21d46eac708bb1a8ff49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 25 Jul 2017 01:33:14 +0300 Subject: [PATCH] Implement Caps::iter_mut() --- gstreamer/src/caps.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 2f6508527..8d1c52417 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -122,9 +122,9 @@ impl CapsRef { Iter::new(self) } - //pub fn iter_mut(&mut self) -> IterMut { - // IterMut::new(self) - //} + pub fn iter_mut(&mut self) -> IterMut { + IterMut::new(self) + } // TODO: All kinds of caps operations } @@ -136,7 +136,7 @@ impl glib::types::StaticType for GstRc { } macro_rules! define_iter( - ($name:ident, $typ:ty, $styp:ty, $getter:ident) => { + ($name:ident, $typ:ty, $styp:ty) => { pub struct $name<'a> { caps: $typ, @@ -164,11 +164,16 @@ impl<'a> Iterator for $name<'a> { return None; } - if let Some(s) = self.caps.$getter(self.idx) { + unsafe { + let structure = ffi::gst_caps_get_structure(self.caps.as_ptr(), self.idx); + if structure.is_null() { + return None; + } + self.idx += 1; - Some(s) - } else { - None + Some(StructureRef::from_glib_borrow_mut( + structure as *mut ffi::GstStructure, + )) } } @@ -190,10 +195,16 @@ impl<'a> DoubleEndedIterator for $name<'a> { } self.n_structures -= 1; - if let Some(s) = self.caps.$getter(self.n_structures) { - Some(s) - } else { - None + + unsafe { + let structure = ffi::gst_caps_get_structure(self.caps.as_ptr(), self.n_structures); + if structure.is_null() { + return None; + } + + Some(StructureRef::from_glib_borrow_mut( + structure as *mut ffi::GstStructure, + )) } } } @@ -202,8 +213,8 @@ impl<'a> ExactSizeIterator for $name<'a> {} } ); -define_iter!(Iter, &'a CapsRef, &'a StructureRef, get_structure); -//define_iter!(IterMut, &'a mut CapsRef, &'a mut Structure, get_mut_structure); +define_iter!(Iter, &'a CapsRef, &'a StructureRef); +define_iter!(IterMut, &'a mut CapsRef, &'a mut StructureRef); impl fmt::Debug for CapsRef { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {