gstreamer: Improve StreamsSelectedBuilder::streams()

It's much easier to use if it takes any kind of iterator instead of a
slice of references.
This commit is contained in:
Sebastian Dröge 2022-02-14 13:44:19 +02:00
parent 98e12e835a
commit d1f978f9f1

View file

@ -2960,7 +2960,7 @@ pub struct StreamsSelectedBuilder<'a> {
collection: &'a crate::StreamCollection, collection: &'a crate::StreamCollection,
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
streams: Option<&'a [&'a crate::Stream]>, streams: Option<Vec<crate::Stream>>,
} }
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
@ -2975,16 +2975,24 @@ impl<'a> StreamsSelectedBuilder<'a> {
} }
} }
pub fn streams(self, streams: &'a [&'a crate::Stream]) -> Self { pub fn streams(
self,
streams: impl IntoIterator<Item = impl std::borrow::Borrow<crate::Stream>>,
) -> Self {
Self { Self {
streams: Some(streams), streams: Some(
streams
.into_iter()
.map(|s| s.borrow().clone())
.collect::<Vec<_>>(),
),
..self ..self
} }
} }
message_builder_generic_impl!(|s: &mut Self, src| { message_builder_generic_impl!(|s: &mut Self, src| {
let msg = ffi::gst_message_new_streams_selected(src, s.collection.to_glib_none().0); let msg = ffi::gst_message_new_streams_selected(src, s.collection.to_glib_none().0);
if let Some(streams) = s.streams { if let Some(ref streams) = s.streams {
for stream in streams { for stream in streams {
ffi::gst_message_streams_selected_add(msg, stream.to_glib_none().0); ffi::gst_message_streams_selected_add(msg, stream.to_glib_none().0);
} }