From e989899467dcb38394dc7998e9cf25b2441e7f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 17 Oct 2021 11:21:31 +0300 Subject: [PATCH] gstreamer: Remove FromIterator impls on references Creating copies silently while calling collect() is unexpected and can explicitly added to the iterator via map() if needed. --- gstreamer/src/bufferlist.rs | 16 ---------------- gstreamer/src/caps.rs | 32 ++------------------------------ 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/gstreamer/src/bufferlist.rs b/gstreamer/src/bufferlist.rs index 73d778b58..7f9fb5c61 100644 --- a/gstreamer/src/bufferlist.rs +++ b/gstreamer/src/bufferlist.rs @@ -281,22 +281,6 @@ impl<'a> IntoIterator for &'a BufferListRef { } } -impl<'a> std::iter::FromIterator<&'a BufferRef> for BufferList { - fn from_iter>(iter: T) -> Self { - assert_initialized_main_thread!(); - let iter = iter.into_iter(); - - let mut list = BufferList::new_sized(iter.size_hint().0); - - { - let list = list.get_mut().unwrap(); - iter.for_each(|b| list.add(b.to_owned())); - } - - list - } -} - impl std::iter::FromIterator for BufferList { fn from_iter>(iter: T) -> Self { assert_initialized_main_thread!(); diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index e7bd16e76..497c918a4 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -144,21 +144,6 @@ impl str::FromStr for Caps { } } -impl<'a> std::iter::FromIterator<&'a StructureRef> 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(|s| caps.append_structure(s.to_owned())); - } - - caps - } -} - impl std::iter::FromIterator for Caps { fn from_iter>(iter: T) -> Self { assert_initialized_main_thread!(); @@ -173,21 +158,6 @@ impl std::iter::FromIterator for Caps { } } -impl<'a, 'b> std::iter::FromIterator<(&'a StructureRef, &'b CapsFeaturesRef)> 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(|(s, f)| caps.append_structure_full(s.to_owned(), Some(f.to_owned()))); - } - - caps - } -} - impl std::iter::FromIterator<(Structure, CapsFeatures)> for Caps { fn from_iter>(iter: T) -> Self { assert_initialized_main_thread!(); @@ -981,12 +951,14 @@ mod tests { let audio = caps .iter() .filter(|s| s.name() == "audio/x-raw") + .map(|s| s.to_owned()) .collect::(); assert_eq!(audio.to_string(), "audio/x-raw"); let audio = caps .iter_with_features() .filter(|(s, _)| s.name() == "audio/x-raw") + .map(|(s, c)| (s.to_owned(), c.to_owned())) .collect::(); assert_eq!(audio.to_string(), "audio/x-raw(ANY)"); }