From 7a12c4d5e1c0e2dd2391dc5534b7fb4dcf773ef8 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Thu, 5 Sep 2019 10:29:16 +0200 Subject: [PATCH] Iterator: Replace ad-hoc fn iter with impl IntoIterator std has a trait for converting things into Iterators. Make use of it. --- gstreamer/src/iterator.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gstreamer/src/iterator.rs b/gstreamer/src/iterator.rs index 632f5491c..7b0aa505e 100644 --- a/gstreamer/src/iterator.rs +++ b/gstreamer/src/iterator.rs @@ -181,10 +181,6 @@ where } } } - - pub fn iter(self) -> StdIterator { - StdIterator::new(self) - } } impl Iterator @@ -491,6 +487,18 @@ impl Drop for Iterator { } } +impl iter::IntoIterator for Iterator +where + for<'a> T: FromValueOptional<'a> + 'static, +{ + type Item = Result; + type IntoIter = StdIterator; + + fn into_iter(self) -> Self::IntoIter { + Self::IntoIter::new(self) + } +} + impl glib::types::StaticType for Iterator { fn static_type() -> glib::types::Type { unsafe { glib::translate::from_glib(gst_sys::gst_iterator_get_type()) } @@ -752,7 +760,7 @@ mod tests { #[test] fn test_std() { - let mut it = Iterator::from_vec(vec![1i32, 2, 3]).iter(); + let mut it = Iterator::from_vec(vec![1i32, 2, 3]).into_iter(); assert_eq!(it.next(), Some(Ok(1))); assert_eq!(it.next(), Some(Ok(2))); assert_eq!(it.next(), Some(Ok(3))); @@ -772,7 +780,7 @@ mod tests { bin.add(&id1).unwrap(); - let mut it = bin.iterate_elements().iter(); + let mut it = bin.iterate_elements().into_iter(); assert_eq!(it.next().unwrap().unwrap(), id1); bin.add(&id2).unwrap(); @@ -803,7 +811,7 @@ mod tests { bin.add(&id1).unwrap(); - let mut it = bin.iterate_elements().iter(); + let mut it = bin.iterate_elements().into_iter(); assert_eq!(it.next().unwrap().unwrap(), id1); bin.add(&id2).unwrap();