diff --git a/audio/audiofx/src/audioecho/ring_buffer.rs b/audio/audiofx/src/audioecho/ring_buffer.rs index fc4265f45..e4a157053 100644 --- a/audio/audiofx/src/audioecho/ring_buffer.rs +++ b/audio/audiofx/src/audioecho/ring_buffer.rs @@ -6,8 +6,6 @@ // // SPDX-License-Identifier: MPL-2.0 -use std::iter; - pub struct RingBuffer { buffer: Box<[f64]>, pos: usize, @@ -16,7 +14,7 @@ pub struct RingBuffer { impl RingBuffer { pub fn new(size: usize) -> Self { let mut buffer = Vec::with_capacity(size); - buffer.extend(iter::repeat(0.0).take(size)); + buffer.extend(std::iter::repeat_n(0.0, size)); Self { buffer: buffer.into_boxed_slice(), diff --git a/audio/audiofx/src/ebur128level/imp.rs b/audio/audiofx/src/ebur128level/imp.rs index e35eb5a07..5c0d6561f 100644 --- a/audio/audiofx/src/ebur128level/imp.rs +++ b/audio/audiofx/src/ebur128level/imp.rs @@ -586,9 +586,9 @@ impl AudioFilterImpl for EbuR128Level { .map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?; } else { // Weight all channels equally if we have no channel map - let channel_map = std::iter::repeat(ebur128::Channel::Center) - .take(info.channels() as usize) - .collect::>(); + let channel_map = + std::iter::repeat_n(ebur128::Channel::Center, info.channels() as usize) + .collect::>(); ebur128 .set_channel_map(&channel_map) .map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?; diff --git a/mux/fmp4/src/fmp4mux/imp.rs b/mux/fmp4/src/fmp4mux/imp.rs index d40381667..f636def26 100644 --- a/mux/fmp4/src/fmp4mux/imp.rs +++ b/mux/fmp4/src/fmp4mux/imp.rs @@ -302,10 +302,7 @@ impl Stream { .filter(|e| e.start.is_some()) .peekable(); while let Some(&mut ref mut elst_info) = iter.next() { - if elst_info - .duration - .map_or(true, |duration| duration.is_zero()) - { + if elst_info.duration.is_none_or(|duration| duration.is_zero()) { elst_info.duration = if let Some(next) = iter.peek_mut() { Some( (next.start.unwrap() - elst_info.start.unwrap()) @@ -630,7 +627,7 @@ impl FMP4Mux { if stream .earliest_pts - .map_or(true, |earliest_pts| earliest_pts > pts) + .is_none_or(|earliest_pts| earliest_pts > pts) { stream.end_pts = Some(pts); } @@ -1025,7 +1022,7 @@ impl FMP4Mux { if earliest_stream .as_ref() - .map_or(true, |(_stream, earliest_running_time)| { + .is_none_or(|(_stream, earliest_running_time)| { *earliest_running_time > running_time }) { @@ -2466,10 +2463,10 @@ impl FMP4Mux { continue; } - if earliest_pts.map_or(true, |earliest_pts| buffer.pts < earliest_pts) { + if earliest_pts.is_none_or(|earliest_pts| buffer.pts < earliest_pts) { earliest_pts = Some(buffer.pts); } - if earliest_pts_position.map_or(true, |earliest_pts_position| { + if earliest_pts_position.is_none_or(|earliest_pts_position| { buffer.buffer.pts().unwrap() < earliest_pts_position }) { earliest_pts_position = Some(buffer.buffer.pts().unwrap()); @@ -2695,8 +2692,7 @@ impl FMP4Mux { if settings.manual_split || all_eos { if let Some(last_gop) = gops.last() { - if chunk_end_pts.map_or(true, |chunk_end_pts| chunk_end_pts < last_gop.end_pts) - { + if chunk_end_pts.is_none_or(|chunk_end_pts| chunk_end_pts < last_gop.end_pts) { chunk_end_pts = Some(last_gop.end_pts); } } diff --git a/mux/mp4/src/mp4mux/boxes.rs b/mux/mp4/src/mp4mux/boxes.rs index 71e489465..05fe3007b 100644 --- a/mux/mp4/src/mp4mux/boxes.rs +++ b/mux/mp4/src/mp4mux/boxes.rs @@ -2087,12 +2087,12 @@ fn write_cslg( }) .fold((None, None), |(min, max), ctts| { ( - if min.map_or(true, |min| ctts < min) { + if min.is_none_or(|min| ctts < min) { Some(ctts) } else { min }, - if max.map_or(true, |max| ctts > max) { + if max.is_none_or(|max| ctts > max) { Some(ctts) } else { max diff --git a/mux/mp4/src/mp4mux/imp.rs b/mux/mp4/src/mp4mux/imp.rs index 419a3c307..e9d9b2bb6 100644 --- a/mux/mp4/src/mp4mux/imp.rs +++ b/mux/mp4/src/mp4mux/imp.rs @@ -197,10 +197,7 @@ impl Stream { .filter(|e| e.start.is_some()) .peekable(); while let Some(&mut ref mut elst_info) = iter.next() { - if elst_info - .duration - .map_or(true, |duration| duration.is_zero()) - { + if elst_info.duration.is_none_or(|duration| duration.is_zero()) { elst_info.duration = if let Some(next) = iter.peek_mut() { Some( (next.start.unwrap() - elst_info.start.unwrap()) @@ -689,7 +686,7 @@ impl MP4Mux { ); let pts = pts + dur; - if stream.end_pts.map_or(true, |end_pts| end_pts < pts) { + if stream.end_pts.is_none_or(|end_pts| end_pts < pts) { gst::trace!(CAT, obj = stream.sinkpad, "Stream end PTS {pts}"); stream.end_pts = Some(pts); } @@ -746,7 +743,7 @@ impl MP4Mux { ); let pts = pts + dur; - if stream.end_pts.map_or(true, |end_pts| end_pts < pts) { + if stream.end_pts.is_none_or(|end_pts| end_pts < pts) { gst::trace!(CAT, obj = stream.sinkpad, "Stream end PTS {pts}"); stream.end_pts = Some(pts); } @@ -833,7 +830,7 @@ impl MP4Mux { if stream .earliest_pts - .map_or(true, |earliest_pts| earliest_pts > pts) + .is_none_or(|earliest_pts| earliest_pts > pts) { gst::debug!(CAT, obj = stream.sinkpad, "Stream earliest PTS {pts}"); stream.earliest_pts = Some(pts); @@ -893,9 +890,9 @@ impl MP4Mux { )); if single_stream - || (settings.interleave_bytes.map_or(true, |interleave_bytes| { + || (settings.interleave_bytes.is_none_or(|interleave_bytes| { interleave_bytes >= stream.queued_chunk_bytes - }) && settings.interleave_time.map_or(true, |interleave_time| { + }) && settings.interleave_time.is_none_or(|interleave_time| { interleave_time >= stream.queued_chunk_time })) { @@ -963,7 +960,7 @@ impl MP4Mux { if earliest_stream .as_ref() - .map_or(true, |(_idx, _stream, earliest_timestamp)| { + .is_none_or(|(_idx, _stream, earliest_timestamp)| { *earliest_timestamp > timestamp }) { diff --git a/net/aws/src/transcriber/imp.rs b/net/aws/src/transcriber/imp.rs index 59248c261..e7baf7861 100644 --- a/net/aws/src/transcriber/imp.rs +++ b/net/aws/src/transcriber/imp.rs @@ -1409,7 +1409,7 @@ impl TranslationPadTask { if self .translate_loop_handle .as_ref() - .map_or(true, task::JoinHandle::is_finished) + .is_none_or(task::JoinHandle::is_finished) { const ERR: &str = "Translate loop is not running"; gst::error!(CAT, imp = self.pad, "{ERR}"); diff --git a/net/mpegtslive/src/mpegtslive/parser.rs b/net/mpegtslive/src/mpegtslive/parser.rs index a4b8338bc..aeab86ee0 100644 --- a/net/mpegtslive/src/mpegtslive/parser.rs +++ b/net/mpegtslive/src/mpegtslive/parser.rs @@ -52,7 +52,7 @@ impl SectionParser { } else if adaptation_field.is_some_and(|af| af.discontinuity_flag) { // discontinuity_flag only defines that there is an expected discountinuity in the // continuity counter but the actual data is continuous - } else if self.cc.map_or(true, |cc| (cc + 1) & 0xf != header.cc) { + } else if self.cc.is_none_or(|cc| (cc + 1) & 0xf != header.cc) { self.clear(); self.waiting_for_pusi = true; // Not start of a payload and we didn't see the start, just return @@ -435,7 +435,7 @@ impl PESParser { } else if adaptation_field.is_some_and(|af| af.discontinuity_flag) { // discontinuity_flag only defines that there is an expected discountinuity in the // continuity counter but the actual data is continuous - } else if self.cc.map_or(true, |cc| (cc + 1) & 0xf != header.cc) { + } else if self.cc.is_none_or(|cc| (cc + 1) & 0xf != header.cc) { self.clear(); self.waiting_for_pusi = true; // Not start of a payload and we didn't see the start, just return diff --git a/net/onvif/src/onvifmetadataparse/imp.rs b/net/onvif/src/onvifmetadataparse/imp.rs index 167ea22eb..399a71f3f 100644 --- a/net/onvif/src/onvifmetadataparse/imp.rs +++ b/net/onvif/src/onvifmetadataparse/imp.rs @@ -198,7 +198,7 @@ impl OnvifMetadataParse { if state .in_segment .position() - .map_or(true, |position| position < pts) + .is_none_or(|position| position < pts) { gst::trace!(CAT, imp = self, "Input position updated to {}", pts); state.in_segment.set_position(pts); @@ -571,7 +571,7 @@ impl OnvifMetadataParse { if state .clock_wait .as_ref() - .map_or(true, |clock_wait| clock_wait.time() != earliest_clock_time) + .is_none_or(|clock_wait| clock_wait.time() != earliest_clock_time) { if let Some(clock_wait) = state.clock_wait.take() { clock_wait.unschedule(); @@ -682,7 +682,7 @@ impl OnvifMetadataParse { if out_segment .position() - .map_or(true, |position| position < current_position) + .is_none_or(|position| position < current_position) { gst::trace!( CAT, @@ -768,7 +768,7 @@ impl OnvifMetadataParse { if out_segment .position() - .map_or(true, |position| position < frame_pts) + .is_none_or(|position| position < frame_pts) { gst::trace!(CAT, imp = self, "Output position updated to {}", frame_pts); out_segment.set_position(frame_pts); @@ -959,7 +959,7 @@ impl OnvifMetadataParse { if state .in_segment .position() - .map_or(true, |position| position < current_position) + .is_none_or(|position| position < current_position) { gst::trace!( CAT, diff --git a/net/rtp/src/rtpbin2/rtprecv.rs b/net/rtp/src/rtpbin2/rtprecv.rs index fe0356541..bb3b5b939 100644 --- a/net/rtp/src/rtpbin2/rtprecv.rs +++ b/net/rtp/src/rtpbin2/rtprecv.rs @@ -149,7 +149,7 @@ impl futures::stream::Stream for JitterBufferStream { return Poll::Ready(Some(item)); } jitterbuffer::PollResult::Timeout(timeout) => { - if lowest_wait.map_or(true, |lowest_wait| timeout < lowest_wait) { + if lowest_wait.is_none_or(|lowest_wait| timeout < lowest_wait) { lowest_wait = Some(timeout); } break; diff --git a/net/rtp/src/rtpbin2/rtpsend.rs b/net/rtp/src/rtpbin2/rtpsend.rs index ba065d54d..e4b461974 100644 --- a/net/rtp/src/rtpbin2/rtpsend.rs +++ b/net/rtp/src/rtpbin2/rtpsend.rs @@ -111,7 +111,7 @@ impl futures::stream::Stream for RtcpSendStream { return Poll::Ready(Some(reply)); } if let Some(wait) = session_inner.session.poll_rtcp_send_timeout(now) { - if lowest_wait.map_or(true, |lowest_wait| wait < lowest_wait) { + if lowest_wait.is_none_or(|lowest_wait| wait < lowest_wait) { lowest_wait = Some(wait); } } diff --git a/net/rtp/src/vp8/depay/imp.rs b/net/rtp/src/vp8/depay/imp.rs index 60659957e..cd85e445f 100644 --- a/net/rtp/src/vp8/depay/imp.rs +++ b/net/rtp/src/vp8/depay/imp.rs @@ -337,7 +337,7 @@ impl crate::basedepay::RtpBaseDepay2Impl for RtpVp8Depay { if state .last_keyframe_frame_header .as_ref() - .map_or(true, |last_frame_header| { + .is_none_or(|last_frame_header| { last_frame_header.profile != frame_header.profile || last_frame_header.resolution != frame_header.resolution }) diff --git a/net/rtp/src/vp8/pay/imp.rs b/net/rtp/src/vp8/pay/imp.rs index 8926dec20..5aa2a65e1 100644 --- a/net/rtp/src/vp8/pay/imp.rs +++ b/net/rtp/src/vp8/pay/imp.rs @@ -483,7 +483,7 @@ impl crate::basepay::RtpBasePay2Impl for RtpVp8Pay { // // FIXME: This is only correct for prediction structures where higher layers always refers // to the previous base layer frame. - if meta.map_or(true, |meta| matches!(meta.layer_id, Some((0, _)))) { + if meta.is_none_or(|meta| matches!(meta.layer_id, Some((0, _)))) { if let Some(ref mut temporal_layer_zero_index) = state.temporal_layer_zero_index { *temporal_layer_zero_index = temporal_layer_zero_index.wrapping_add(1); gst::trace!( diff --git a/net/rtp/src/vp9/depay/imp.rs b/net/rtp/src/vp9/depay/imp.rs index a0d3febd4..5eec9876f 100644 --- a/net/rtp/src/vp9/depay/imp.rs +++ b/net/rtp/src/vp9/depay/imp.rs @@ -298,7 +298,7 @@ impl crate::basedepay::RtpBaseDepay2Impl for RtpVp9Depay { && payload_descriptor .layer_index .as_ref() - .map_or(true, |layer_index| layer_index.spatial_layer_id == 0); + .is_none_or(|layer_index| layer_index.spatial_layer_id == 0); // Additionally, this is a key picture if it is not an inter predicted picture. let is_key_picture = @@ -509,8 +509,7 @@ impl crate::basedepay::RtpBaseDepay2Impl for RtpVp9Depay { if let Some(current_keyframe_frame_header) = state.current_keyframe_frame_header.take() { // TODO: Could also add more information to the caps if current_keyframe_frame_header.keyframe_info.is_some() - && state.last_keyframe_frame_header.as_ref().map_or( - true, + && state.last_keyframe_frame_header.as_ref().is_none_or( |last_keyframe_frame_header| { last_keyframe_frame_header.profile != current_keyframe_frame_header.profile || last_keyframe_frame_header diff --git a/utils/fallbackswitch/src/fallbacksrc/imp.rs b/utils/fallbackswitch/src/fallbacksrc/imp.rs index 9cdb2efed..a59ab2428 100644 --- a/utils/fallbackswitch/src/fallbacksrc/imp.rs +++ b/utils/fallbackswitch/src/fallbacksrc/imp.rs @@ -2319,7 +2319,7 @@ impl FallbackSrc { o.main_branch .as_ref() // no main branch = ignore - .map_or(true, |b| { + .is_none_or(|b| { &b.queue_srcpad == pad // now check if the pad is EOS && b.queue_srcpad.pad_flags().contains(gst::PadFlags::EOS) @@ -2659,7 +2659,7 @@ impl FallbackSrc { } let running_time = running_time.unwrap(); - if min_running_time.map_or(true, |min_running_time| running_time < min_running_time) { + if min_running_time.is_none_or(|min_running_time| running_time < min_running_time) { min_running_time = Some(running_time); } } diff --git a/utils/fallbackswitch/tests/fallbackswitch.rs b/utils/fallbackswitch/tests/fallbackswitch.rs index a99b4b3ba..e9c3bfe4c 100644 --- a/utils/fallbackswitch/tests/fallbackswitch.rs +++ b/utils/fallbackswitch/tests/fallbackswitch.rs @@ -570,7 +570,7 @@ fn setup_pipeline( // FIXME probably can expect clock.time() clock .time() - .map_or(true, |clock_time| clock_time < clock_id.time()) + .is_none_or(|clock_time| clock_time < clock_id.time()) }) { use std::{thread, time}; diff --git a/utils/togglerecord/src/togglerecord/imp.rs b/utils/togglerecord/src/togglerecord/imp.rs index 5191de121..ad17e5845 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -1626,9 +1626,7 @@ impl ToggleRecord { let mut state = stream.state.lock(); state.eos = true; - let main_is_eos = main_state - .as_ref() - .map_or(true, |main_state| main_state.eos); + let main_is_eos = main_state.as_ref().is_none_or(|main_state| main_state.eos); drop(main_state); if main_is_eos { diff --git a/utils/uriplaylistbin/tests/uriplaylistbin.rs b/utils/uriplaylistbin/tests/uriplaylistbin.rs index 930428a1f..3489eaa88 100644 --- a/utils/uriplaylistbin/tests/uriplaylistbin.rs +++ b/utils/uriplaylistbin/tests/uriplaylistbin.rs @@ -271,9 +271,7 @@ fn test( // check stream-collection and streams-selected message ordering let mut events = events.clone().into_iter(); - let playlist = std::iter::repeat(medias.iter()) - .take(iterations as usize) - .flatten(); + let playlist = std::iter::repeat_n(medias.iter(), iterations as usize).flatten(); let mut last_media = None; for media in playlist { @@ -281,7 +279,7 @@ fn test( if last_media .as_ref() - .map_or(true, |last_media| *last_media != media) + .is_none_or(|last_media| *last_media != media) { last_media = Some(media); media_changed = true; diff --git a/video/closedcaption/src/ccdetect/imp.rs b/video/closedcaption/src/ccdetect/imp.rs index fd6dc1e6a..228c8ea04 100644 --- a/video/closedcaption/src/ccdetect/imp.rs +++ b/video/closedcaption/src/ccdetect/imp.rs @@ -171,9 +171,9 @@ impl CCDetect { ); if cc_packet.cc608 != settings.cc608 { - let changed = state.last_cc608_change.map_or(true, |last_cc608_change| { - ts > last_cc608_change + settings.window - }); + let changed = state + .last_cc608_change + .is_none_or(|last_cc608_change| ts > last_cc608_change + settings.window); if changed { settings.cc608 = cc_packet.cc608; @@ -185,9 +185,9 @@ impl CCDetect { } if cc_packet.cc708 != settings.cc708 { - let changed = state.last_cc708_change.map_or(true, |last_cc708_change| { - ts > last_cc708_change + settings.window - }); + let changed = state + .last_cc708_change + .is_none_or(|last_cc708_change| ts > last_cc708_change + settings.window); if changed { settings.cc708 = cc_packet.cc708; state.last_cc708_change = Some(ts); diff --git a/video/closedcaption/src/jsontovtt/imp.rs b/video/closedcaption/src/jsontovtt/imp.rs index 553a116a7..e217d8ec2 100644 --- a/video/closedcaption/src/jsontovtt/imp.rs +++ b/video/closedcaption/src/jsontovtt/imp.rs @@ -235,7 +235,7 @@ impl State { if self .settings .timeout - .map_or(true, |timeout| running_time < line_running_time + timeout) + .is_none_or(|timeout| running_time < line_running_time + timeout) { let mut cloned = drained_line.clone(); cloned.pts = end_pts; diff --git a/video/closedcaption/src/mcc_parse/imp.rs b/video/closedcaption/src/mcc_parse/imp.rs index fd9caa85e..e1a2602b8 100644 --- a/video/closedcaption/src/mcc_parse/imp.rs +++ b/video/closedcaption/src/mcc_parse/imp.rs @@ -204,7 +204,7 @@ impl State { if self .last_position - .map_or(true, |last_position| nsecs >= last_position) + .is_none_or(|last_position| nsecs >= last_position) { self.last_position = Some(nsecs); } else { diff --git a/video/closedcaption/src/scc_parse/imp.rs b/video/closedcaption/src/scc_parse/imp.rs index d0e214bf2..506044ee3 100644 --- a/video/closedcaption/src/scc_parse/imp.rs +++ b/video/closedcaption/src/scc_parse/imp.rs @@ -179,7 +179,7 @@ impl State { if self .last_position - .map_or(true, |last_position| nsecs >= last_position) + .is_none_or(|last_position| nsecs >= last_position) { self.last_position = Some(nsecs); } else { diff --git a/video/closedcaption/src/st2038ancdemux/imp.rs b/video/closedcaption/src/st2038ancdemux/imp.rs index f4bcc17f9..8d564e6ca 100644 --- a/video/closedcaption/src/st2038ancdemux/imp.rs +++ b/video/closedcaption/src/st2038ancdemux/imp.rs @@ -179,7 +179,7 @@ impl St2038AncDemux { if let Some(running_time) = running_time { if stream .last_used - .map_or(true, |last_used| last_used < running_time) + .is_none_or(|last_used| last_used < running_time) { stream.last_used = Some(running_time); } diff --git a/video/closedcaption/src/st2038ancmux/imp.rs b/video/closedcaption/src/st2038ancmux/imp.rs index 7a0923285..f6d967c4a 100644 --- a/video/closedcaption/src/st2038ancmux/imp.rs +++ b/video/closedcaption/src/st2038ancmux/imp.rs @@ -155,7 +155,7 @@ impl AggregatorImpl for St2038AncMux { "Buffer starting at {buffer_start_ts} >= {end_running_time}" ); - if min_next_buffer_running_time.map_or(true, |next_buffer_min_running_time| { + if min_next_buffer_running_time.is_none_or(|next_buffer_min_running_time| { next_buffer_min_running_time > buffer_start_ts }) { min_next_buffer_running_time = Some(buffer_start_ts);