Fix various new clippy warnings because of the MSRV bump

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2203>
This commit is contained in:
Sebastian Dröge 2025-04-14 11:33:06 +03:00
parent 13ea188b74
commit 594fbfd649
23 changed files with 50 additions and 64 deletions

View file

@ -6,8 +6,6 @@
// //
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use std::iter;
pub struct RingBuffer { pub struct RingBuffer {
buffer: Box<[f64]>, buffer: Box<[f64]>,
pos: usize, pos: usize,
@ -16,7 +14,7 @@ pub struct RingBuffer {
impl RingBuffer { impl RingBuffer {
pub fn new(size: usize) -> Self { pub fn new(size: usize) -> Self {
let mut buffer = Vec::with_capacity(size); 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 { Self {
buffer: buffer.into_boxed_slice(), buffer: buffer.into_boxed_slice(),

View file

@ -586,9 +586,9 @@ impl AudioFilterImpl for EbuR128Level {
.map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?; .map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?;
} else { } else {
// Weight all channels equally if we have no channel map // Weight all channels equally if we have no channel map
let channel_map = std::iter::repeat(ebur128::Channel::Center) let channel_map =
.take(info.channels() as usize) std::iter::repeat_n(ebur128::Channel::Center, info.channels() as usize)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
ebur128 ebur128
.set_channel_map(&channel_map) .set_channel_map(&channel_map)
.map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?; .map_err(|err| gst::loggable_error!(CAT, "Failed to set channel map: {}", err))?;

View file

@ -302,10 +302,7 @@ impl Stream {
.filter(|e| e.start.is_some()) .filter(|e| e.start.is_some())
.peekable(); .peekable();
while let Some(&mut ref mut elst_info) = iter.next() { while let Some(&mut ref mut elst_info) = iter.next() {
if elst_info if elst_info.duration.is_none_or(|duration| duration.is_zero()) {
.duration
.map_or(true, |duration| duration.is_zero())
{
elst_info.duration = if let Some(next) = iter.peek_mut() { elst_info.duration = if let Some(next) = iter.peek_mut() {
Some( Some(
(next.start.unwrap() - elst_info.start.unwrap()) (next.start.unwrap() - elst_info.start.unwrap())
@ -630,7 +627,7 @@ impl FMP4Mux {
if stream if stream
.earliest_pts .earliest_pts
.map_or(true, |earliest_pts| earliest_pts > pts) .is_none_or(|earliest_pts| earliest_pts > pts)
{ {
stream.end_pts = Some(pts); stream.end_pts = Some(pts);
} }
@ -1025,7 +1022,7 @@ impl FMP4Mux {
if earliest_stream if earliest_stream
.as_ref() .as_ref()
.map_or(true, |(_stream, earliest_running_time)| { .is_none_or(|(_stream, earliest_running_time)| {
*earliest_running_time > running_time *earliest_running_time > running_time
}) })
{ {
@ -2466,10 +2463,10 @@ impl FMP4Mux {
continue; 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); 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 buffer.buffer.pts().unwrap() < earliest_pts_position
}) { }) {
earliest_pts_position = Some(buffer.buffer.pts().unwrap()); earliest_pts_position = Some(buffer.buffer.pts().unwrap());
@ -2695,8 +2692,7 @@ impl FMP4Mux {
if settings.manual_split || all_eos { if settings.manual_split || all_eos {
if let Some(last_gop) = gops.last() { 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); chunk_end_pts = Some(last_gop.end_pts);
} }
} }

View file

@ -2087,12 +2087,12 @@ fn write_cslg(
}) })
.fold((None, None), |(min, max), ctts| { .fold((None, None), |(min, max), ctts| {
( (
if min.map_or(true, |min| ctts < min) { if min.is_none_or(|min| ctts < min) {
Some(ctts) Some(ctts)
} else { } else {
min min
}, },
if max.map_or(true, |max| ctts > max) { if max.is_none_or(|max| ctts > max) {
Some(ctts) Some(ctts)
} else { } else {
max max

View file

@ -197,10 +197,7 @@ impl Stream {
.filter(|e| e.start.is_some()) .filter(|e| e.start.is_some())
.peekable(); .peekable();
while let Some(&mut ref mut elst_info) = iter.next() { while let Some(&mut ref mut elst_info) = iter.next() {
if elst_info if elst_info.duration.is_none_or(|duration| duration.is_zero()) {
.duration
.map_or(true, |duration| duration.is_zero())
{
elst_info.duration = if let Some(next) = iter.peek_mut() { elst_info.duration = if let Some(next) = iter.peek_mut() {
Some( Some(
(next.start.unwrap() - elst_info.start.unwrap()) (next.start.unwrap() - elst_info.start.unwrap())
@ -689,7 +686,7 @@ impl MP4Mux {
); );
let pts = pts + dur; 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}"); gst::trace!(CAT, obj = stream.sinkpad, "Stream end PTS {pts}");
stream.end_pts = Some(pts); stream.end_pts = Some(pts);
} }
@ -746,7 +743,7 @@ impl MP4Mux {
); );
let pts = pts + dur; 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}"); gst::trace!(CAT, obj = stream.sinkpad, "Stream end PTS {pts}");
stream.end_pts = Some(pts); stream.end_pts = Some(pts);
} }
@ -833,7 +830,7 @@ impl MP4Mux {
if stream if stream
.earliest_pts .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}"); gst::debug!(CAT, obj = stream.sinkpad, "Stream earliest PTS {pts}");
stream.earliest_pts = Some(pts); stream.earliest_pts = Some(pts);
@ -893,9 +890,9 @@ impl MP4Mux {
)); ));
if single_stream 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 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 interleave_time >= stream.queued_chunk_time
})) }))
{ {
@ -963,7 +960,7 @@ impl MP4Mux {
if earliest_stream if earliest_stream
.as_ref() .as_ref()
.map_or(true, |(_idx, _stream, earliest_timestamp)| { .is_none_or(|(_idx, _stream, earliest_timestamp)| {
*earliest_timestamp > timestamp *earliest_timestamp > timestamp
}) })
{ {

View file

@ -1409,7 +1409,7 @@ impl TranslationPadTask {
if self if self
.translate_loop_handle .translate_loop_handle
.as_ref() .as_ref()
.map_or(true, task::JoinHandle::is_finished) .is_none_or(task::JoinHandle::is_finished)
{ {
const ERR: &str = "Translate loop is not running"; const ERR: &str = "Translate loop is not running";
gst::error!(CAT, imp = self.pad, "{ERR}"); gst::error!(CAT, imp = self.pad, "{ERR}");

View file

@ -52,7 +52,7 @@ impl SectionParser {
} else if adaptation_field.is_some_and(|af| af.discontinuity_flag) { } else if adaptation_field.is_some_and(|af| af.discontinuity_flag) {
// discontinuity_flag only defines that there is an expected discountinuity in the // discontinuity_flag only defines that there is an expected discountinuity in the
// continuity counter but the actual data is continuous // 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.clear();
self.waiting_for_pusi = true; self.waiting_for_pusi = true;
// Not start of a payload and we didn't see the start, just return // 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) { } else if adaptation_field.is_some_and(|af| af.discontinuity_flag) {
// discontinuity_flag only defines that there is an expected discountinuity in the // discontinuity_flag only defines that there is an expected discountinuity in the
// continuity counter but the actual data is continuous // 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.clear();
self.waiting_for_pusi = true; self.waiting_for_pusi = true;
// Not start of a payload and we didn't see the start, just return // Not start of a payload and we didn't see the start, just return

View file

@ -198,7 +198,7 @@ impl OnvifMetadataParse {
if state if state
.in_segment .in_segment
.position() .position()
.map_or(true, |position| position < pts) .is_none_or(|position| position < pts)
{ {
gst::trace!(CAT, imp = self, "Input position updated to {}", pts); gst::trace!(CAT, imp = self, "Input position updated to {}", pts);
state.in_segment.set_position(pts); state.in_segment.set_position(pts);
@ -571,7 +571,7 @@ impl OnvifMetadataParse {
if state if state
.clock_wait .clock_wait
.as_ref() .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() { if let Some(clock_wait) = state.clock_wait.take() {
clock_wait.unschedule(); clock_wait.unschedule();
@ -682,7 +682,7 @@ impl OnvifMetadataParse {
if out_segment if out_segment
.position() .position()
.map_or(true, |position| position < current_position) .is_none_or(|position| position < current_position)
{ {
gst::trace!( gst::trace!(
CAT, CAT,
@ -768,7 +768,7 @@ impl OnvifMetadataParse {
if out_segment if out_segment
.position() .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); gst::trace!(CAT, imp = self, "Output position updated to {}", frame_pts);
out_segment.set_position(frame_pts); out_segment.set_position(frame_pts);
@ -959,7 +959,7 @@ impl OnvifMetadataParse {
if state if state
.in_segment .in_segment
.position() .position()
.map_or(true, |position| position < current_position) .is_none_or(|position| position < current_position)
{ {
gst::trace!( gst::trace!(
CAT, CAT,

View file

@ -149,7 +149,7 @@ impl futures::stream::Stream for JitterBufferStream {
return Poll::Ready(Some(item)); return Poll::Ready(Some(item));
} }
jitterbuffer::PollResult::Timeout(timeout) => { 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); lowest_wait = Some(timeout);
} }
break; break;

View file

@ -111,7 +111,7 @@ impl futures::stream::Stream for RtcpSendStream {
return Poll::Ready(Some(reply)); return Poll::Ready(Some(reply));
} }
if let Some(wait) = session_inner.session.poll_rtcp_send_timeout(now) { 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); lowest_wait = Some(wait);
} }
} }

View file

@ -337,7 +337,7 @@ impl crate::basedepay::RtpBaseDepay2Impl for RtpVp8Depay {
if state if state
.last_keyframe_frame_header .last_keyframe_frame_header
.as_ref() .as_ref()
.map_or(true, |last_frame_header| { .is_none_or(|last_frame_header| {
last_frame_header.profile != frame_header.profile last_frame_header.profile != frame_header.profile
|| last_frame_header.resolution != frame_header.resolution || last_frame_header.resolution != frame_header.resolution
}) })

View file

@ -483,7 +483,7 @@ impl crate::basepay::RtpBasePay2Impl for RtpVp8Pay {
// //
// FIXME: This is only correct for prediction structures where higher layers always refers // FIXME: This is only correct for prediction structures where higher layers always refers
// to the previous base layer frame. // 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 { 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); *temporal_layer_zero_index = temporal_layer_zero_index.wrapping_add(1);
gst::trace!( gst::trace!(

View file

@ -298,7 +298,7 @@ impl crate::basedepay::RtpBaseDepay2Impl for RtpVp9Depay {
&& payload_descriptor && payload_descriptor
.layer_index .layer_index
.as_ref() .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. // Additionally, this is a key picture if it is not an inter predicted picture.
let is_key_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() { if let Some(current_keyframe_frame_header) = state.current_keyframe_frame_header.take() {
// TODO: Could also add more information to the caps // TODO: Could also add more information to the caps
if current_keyframe_frame_header.keyframe_info.is_some() if current_keyframe_frame_header.keyframe_info.is_some()
&& state.last_keyframe_frame_header.as_ref().map_or( && state.last_keyframe_frame_header.as_ref().is_none_or(
true,
|last_keyframe_frame_header| { |last_keyframe_frame_header| {
last_keyframe_frame_header.profile != current_keyframe_frame_header.profile last_keyframe_frame_header.profile != current_keyframe_frame_header.profile
|| last_keyframe_frame_header || last_keyframe_frame_header

View file

@ -2319,7 +2319,7 @@ impl FallbackSrc {
o.main_branch o.main_branch
.as_ref() .as_ref()
// no main branch = ignore // no main branch = ignore
.map_or(true, |b| { .is_none_or(|b| {
&b.queue_srcpad == pad &b.queue_srcpad == pad
// now check if the pad is EOS // now check if the pad is EOS
&& b.queue_srcpad.pad_flags().contains(gst::PadFlags::EOS) && b.queue_srcpad.pad_flags().contains(gst::PadFlags::EOS)
@ -2659,7 +2659,7 @@ impl FallbackSrc {
} }
let running_time = running_time.unwrap(); 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); min_running_time = Some(running_time);
} }
} }

View file

@ -570,7 +570,7 @@ fn setup_pipeline(
// FIXME probably can expect clock.time() // FIXME probably can expect clock.time()
clock clock
.time() .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}; use std::{thread, time};

View file

@ -1626,9 +1626,7 @@ impl ToggleRecord {
let mut state = stream.state.lock(); let mut state = stream.state.lock();
state.eos = true; state.eos = true;
let main_is_eos = main_state let main_is_eos = main_state.as_ref().is_none_or(|main_state| main_state.eos);
.as_ref()
.map_or(true, |main_state| main_state.eos);
drop(main_state); drop(main_state);
if main_is_eos { if main_is_eos {

View file

@ -271,9 +271,7 @@ fn test(
// check stream-collection and streams-selected message ordering // check stream-collection and streams-selected message ordering
let mut events = events.clone().into_iter(); let mut events = events.clone().into_iter();
let playlist = std::iter::repeat(medias.iter()) let playlist = std::iter::repeat_n(medias.iter(), iterations as usize).flatten();
.take(iterations as usize)
.flatten();
let mut last_media = None; let mut last_media = None;
for media in playlist { for media in playlist {
@ -281,7 +279,7 @@ fn test(
if last_media if last_media
.as_ref() .as_ref()
.map_or(true, |last_media| *last_media != media) .is_none_or(|last_media| *last_media != media)
{ {
last_media = Some(media); last_media = Some(media);
media_changed = true; media_changed = true;

View file

@ -171,9 +171,9 @@ impl CCDetect {
); );
if cc_packet.cc608 != settings.cc608 { if cc_packet.cc608 != settings.cc608 {
let changed = state.last_cc608_change.map_or(true, |last_cc608_change| { let changed = state
ts > last_cc608_change + settings.window .last_cc608_change
}); .is_none_or(|last_cc608_change| ts > last_cc608_change + settings.window);
if changed { if changed {
settings.cc608 = cc_packet.cc608; settings.cc608 = cc_packet.cc608;
@ -185,9 +185,9 @@ impl CCDetect {
} }
if cc_packet.cc708 != settings.cc708 { if cc_packet.cc708 != settings.cc708 {
let changed = state.last_cc708_change.map_or(true, |last_cc708_change| { let changed = state
ts > last_cc708_change + settings.window .last_cc708_change
}); .is_none_or(|last_cc708_change| ts > last_cc708_change + settings.window);
if changed { if changed {
settings.cc708 = cc_packet.cc708; settings.cc708 = cc_packet.cc708;
state.last_cc708_change = Some(ts); state.last_cc708_change = Some(ts);

View file

@ -235,7 +235,7 @@ impl State {
if self if self
.settings .settings
.timeout .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(); let mut cloned = drained_line.clone();
cloned.pts = end_pts; cloned.pts = end_pts;

View file

@ -204,7 +204,7 @@ impl State {
if self if self
.last_position .last_position
.map_or(true, |last_position| nsecs >= last_position) .is_none_or(|last_position| nsecs >= last_position)
{ {
self.last_position = Some(nsecs); self.last_position = Some(nsecs);
} else { } else {

View file

@ -179,7 +179,7 @@ impl State {
if self if self
.last_position .last_position
.map_or(true, |last_position| nsecs >= last_position) .is_none_or(|last_position| nsecs >= last_position)
{ {
self.last_position = Some(nsecs); self.last_position = Some(nsecs);
} else { } else {

View file

@ -179,7 +179,7 @@ impl St2038AncDemux {
if let Some(running_time) = running_time { if let Some(running_time) = running_time {
if stream if stream
.last_used .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); stream.last_used = Some(running_time);
} }

View file

@ -155,7 +155,7 @@ impl AggregatorImpl for St2038AncMux {
"Buffer starting at {buffer_start_ts} >= {end_running_time}" "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 next_buffer_min_running_time > buffer_start_ts
}) { }) {
min_next_buffer_running_time = Some(buffer_start_ts); min_next_buffer_running_time = Some(buffer_start_ts);