From 493175742f4bc4c580551378add717ddb0101d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 28 Mar 2025 12:42:06 +0200 Subject: [PATCH] Add #[must_use] annotation to all iterator structs Part-of: --- gstreamer-analytics/src/classification.rs | 1 + gstreamer-analytics/src/relation_meta.rs | 1 + gstreamer-audio/src/audio_format.rs | 1 + gstreamer-pbutils/src/discoverer_stream_info.rs | 1 + gstreamer-sdp/src/sdp_media.rs | 1 + gstreamer-sdp/src/sdp_message.rs | 2 ++ gstreamer-video/src/video_format.rs | 1 + gstreamer-video/src/video_meta.rs | 1 + gstreamer-video/src/video_overlay_composition.rs | 1 + gstreamer-video/src/video_vbi_parser.rs | 1 + gstreamer/src/buffer.rs | 2 ++ gstreamer/src/bus.rs | 1 + gstreamer/src/iterator.rs | 1 + gstreamer/src/structure.rs | 2 ++ gstreamer/src/tags.rs | 4 ++++ gstreamer/src/utils.rs | 1 + 16 files changed, 22 insertions(+) diff --git a/gstreamer-analytics/src/classification.rs b/gstreamer-analytics/src/classification.rs index 1f95e0b52..ec13a4a66 100644 --- a/gstreamer-analytics/src/classification.rs +++ b/gstreamer-analytics/src/classification.rs @@ -133,6 +133,7 @@ impl AnalyticsMtdRef<'_, AnalyticsClassificationMtd> { } } +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct AnalyticsClassificationIterator<'a> { mtd: &'a AnalyticsMtdRef<'a, AnalyticsClassificationMtd>, index: usize, diff --git a/gstreamer-analytics/src/relation_meta.rs b/gstreamer-analytics/src/relation_meta.rs index 2b619960f..f198bc8d5 100644 --- a/gstreamer-analytics/src/relation_meta.rs +++ b/gstreamer-analytics/src/relation_meta.rs @@ -468,6 +468,7 @@ impl<'a, T: AnalyticsMtd> AsRef> for AnalyticsMtdRefMut<' macro_rules! define_mtd_iter { ($name:ident, $metaref:ty, $itemref:ty, $copy_meta:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct $name<'a, T: AnalyticsMtd> { meta: $metaref, state: glib::ffi::gpointer, diff --git a/gstreamer-audio/src/audio_format.rs b/gstreamer-audio/src/audio_format.rs index 93ea97bb4..1fb75fb77 100644 --- a/gstreamer-audio/src/audio_format.rs +++ b/gstreamer-audio/src/audio_format.rs @@ -225,6 +225,7 @@ pub const AUDIO_FORMAT_F32: crate::AudioFormat = crate::AudioFormat::F32le; #[cfg(target_endian = "little")] pub const AUDIO_FORMAT_F64: crate::AudioFormat = crate::AudioFormat::F64le; +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct AudioFormatIterator { idx: usize, len: usize, diff --git a/gstreamer-pbutils/src/discoverer_stream_info.rs b/gstreamer-pbutils/src/discoverer_stream_info.rs index 79f0646e7..670f38475 100644 --- a/gstreamer-pbutils/src/discoverer_stream_info.rs +++ b/gstreamer-pbutils/src/discoverer_stream_info.rs @@ -3,6 +3,7 @@ use std::fmt; use crate::{prelude::*, DiscovererStreamInfo}; +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct Iter { stream_info: Option, diff --git a/gstreamer-sdp/src/sdp_media.rs b/gstreamer-sdp/src/sdp_media.rs index e56701acd..3a09aaa20 100644 --- a/gstreamer-sdp/src/sdp_media.rs +++ b/gstreamer-sdp/src/sdp_media.rs @@ -651,6 +651,7 @@ impl ToOwned for SDPMediaRef { macro_rules! define_iter( ($name:ident, $typ:ty, $get_item:expr, $get_len:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct $name<'a> { media: &'a SDPMediaRef, diff --git a/gstreamer-sdp/src/sdp_message.rs b/gstreamer-sdp/src/sdp_message.rs index 67ac3d6ef..4cb1bf8d6 100644 --- a/gstreamer-sdp/src/sdp_message.rs +++ b/gstreamer-sdp/src/sdp_message.rs @@ -1007,6 +1007,7 @@ impl glib::value::ToValueOptional for SDPMessageRef { macro_rules! define_iter( ($name:ident, $typ:ty, $get_item:expr, $get_len:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct $name<'a> { message: &'a SDPMessageRef, @@ -1103,6 +1104,7 @@ macro_rules! define_iter( macro_rules! define_iter_mut( ($name:ident, $typ:ty, $get_item:expr, $get_len:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct $name<'a> { message: &'a mut SDPMessageRef, diff --git a/gstreamer-video/src/video_format.rs b/gstreamer-video/src/video_format.rs index 97193dcf9..81324fafd 100644 --- a/gstreamer-video/src/video_format.rs +++ b/gstreamer-video/src/video_format.rs @@ -336,6 +336,7 @@ impl Ord for crate::VideoFormat { } } +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct VideoFormatIterator { idx: usize, len: usize, diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index 224e39a9c..308b6a05e 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -415,6 +415,7 @@ impl VideoRegionOfInterestMeta { } } +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct ParamsIter<'a> { _meta: &'a VideoRegionOfInterestMeta, list: Option>, diff --git a/gstreamer-video/src/video_overlay_composition.rs b/gstreamer-video/src/video_overlay_composition.rs index 4fb764f93..045f971a7 100644 --- a/gstreamer-video/src/video_overlay_composition.rs +++ b/gstreamer-video/src/video_overlay_composition.rs @@ -454,6 +454,7 @@ impl<'a> std::iter::FromIterator<&'a VideoOverlayRectangle> for VideoOverlayComp } } +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct Iter<'a> { composition: &'a VideoOverlayCompositionRef, idx: usize, diff --git a/gstreamer-video/src/video_vbi_parser.rs b/gstreamer-video/src/video_vbi_parser.rs index 0a916662a..ca89efd4e 100644 --- a/gstreamer-video/src/video_vbi_parser.rs +++ b/gstreamer-video/src/video_vbi_parser.rs @@ -152,6 +152,7 @@ impl<'a> TryFrom<&'a crate::VideoInfo> for VideoVBIParser { } } +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct AncillaryIter<'a> { parser: &'a mut VideoVBIParser, diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index dd3fcb254..c6c4029c6 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -873,6 +873,7 @@ impl BufferRef { macro_rules! define_meta_iter( ($name:ident, $typ:ty, $mtyp:ty, $prepare_buffer:expr, $from_ptr:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct $name<'a, T: MetaAPI + 'a> { buffer: $typ, state: glib::ffi::gpointer, @@ -1331,6 +1332,7 @@ pub struct Dump<'a> { end: Bound, } +#[must_use = "iterators are lazy and do nothing unless consumed"] struct BufferChunked16Iter<'a> { buffer: &'a BufferRef, mem_idx: usize, diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 09c411b78..fefb6d154 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -320,6 +320,7 @@ impl Bus { } } +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct Iter<'a> { bus: &'a Bus, diff --git a/gstreamer/src/iterator.rs b/gstreamer/src/iterator.rs index d8b706f19..7de13b6f6 100644 --- a/gstreamer/src/iterator.rs +++ b/gstreamer/src/iterator.rs @@ -694,6 +694,7 @@ impl glib::translate::FromGlibPtrFull<*mut ffi::GstIterator> for } } +#[must_use = "iterators are lazy and do nothing unless consumed"] pub struct StdIterator { inner: Iterator, error: Option, diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 54e560086..6a37a6b46 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -1780,6 +1780,7 @@ crate::utils::define_fixed_size_iter!( } ); +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct Iter<'a> { iter: FieldIterator<'a>, @@ -1844,6 +1845,7 @@ impl ExactSizeIterator for Iter<'_> {} impl std::iter::FusedIterator for Iter<'_> {} #[cfg(feature = "v1_26")] +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct IdIter<'a> { iter: FieldIdIterator<'a>, diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index 1c034e408..43d4c7f7e 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -635,6 +635,7 @@ impl PartialEq for TagListRef { impl Eq for TagListRef {} +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct TagIter<'a, T: Tag<'a>> { taglist: &'a TagListRef, @@ -743,6 +744,7 @@ where { } +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct GenericTagIter<'a> { taglist: &'a TagListRef, @@ -837,6 +839,7 @@ impl ExactSizeIterator for GenericTagIter<'_> {} impl std::iter::FusedIterator for GenericTagIter<'_> {} +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct GenericIter<'a> { taglist: &'a TagListRef, @@ -931,6 +934,7 @@ impl ExactSizeIterator for GenericIter<'_> {} impl std::iter::FusedIterator for GenericIter<'_> {} +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct Iter<'a> { taglist: &'a TagListRef, diff --git a/gstreamer/src/utils.rs b/gstreamer/src/utils.rs index 60e01e47b..a7ebbc6ef 100644 --- a/gstreamer/src/utils.rs +++ b/gstreamer/src/utils.rs @@ -81,6 +81,7 @@ where macro_rules! define_fixed_size_iter( ($name:ident, $typ:ty, $ityp:ty, $get_len:expr, $get_item:expr) => { + #[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct $name<'a> { pub(crate) collection: $typ,