From bdadf25f5cc9dac6593157d9fa4614f793591790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Sun, 24 Nov 2019 23:00:27 +0100 Subject: [PATCH] Clippy pass --- gst-plugin-cdg/src/cdgdec.rs | 5 ++- gst-plugin-closedcaption/src/mcc_parse.rs | 33 +++++++++---------- .../src/fallbackswitch.rs | 4 +-- gst-plugin-lewton/src/lewtondec.rs | 2 +- gst-plugin-rav1e/src/rav1enc.rs | 11 ++----- gst-plugin-reqwest/src/reqwesthttpsrc.rs | 7 ++-- gst-plugin-rusoto/src/s3sink.rs | 25 +++++++------- gst-plugin-rusoto/src/s3src.rs | 23 ++++++------- gst-plugin-togglerecord/src/togglerecord.rs | 6 ++-- gst-plugin-tutorial/src/sinesrc.rs | 7 ++-- gst-plugin-version-helper/src/lib.rs | 6 ++-- 11 files changed, 56 insertions(+), 73 deletions(-) diff --git a/gst-plugin-cdg/src/cdgdec.rs b/gst-plugin-cdg/src/cdgdec.rs index 98b9f314..c1abb7b8 100644 --- a/gst-plugin-cdg/src/cdgdec.rs +++ b/gst-plugin-cdg/src/cdgdec.rs @@ -195,7 +195,10 @@ impl VideoDecoderImpl for CdgDec { query: &mut gst::QueryRef, ) -> Result<(), gst::ErrorMessage> { if let gst::query::QueryView::Allocation(allocation) = query.view() { - if let Some(_) = allocation.find_allocation_meta::() { + if allocation + .find_allocation_meta::() + .is_some() + { let pools = allocation.get_allocation_pools(); if let Some((ref pool, _, _, _)) = pools.first() { if let Some(pool) = pool { diff --git a/gst-plugin-closedcaption/src/mcc_parse.rs b/gst-plugin-closedcaption/src/mcc_parse.rs index 3f7e6c9d..1aac0a86 100644 --- a/gst-plugin-closedcaption/src/mcc_parse.rs +++ b/gst-plugin-closedcaption/src/mcc_parse.rs @@ -673,7 +673,7 @@ impl MccParse { fn start_task(&self, element: &gst::Element) -> Result<(), gst::LoggableError> { let element_weak = element.downgrade(); let pad_weak = self.sinkpad.downgrade(); - if let Err(_) = self.sinkpad.start_task(move || { + let res = self.sinkpad.start_task(move || { let element = match element_weak.upgrade() { Some(element) => element, None => { @@ -686,7 +686,8 @@ impl MccParse { let parse = Self::from_instance(&element); parse.loop_fn(&element); - }) { + }); + if res.is_err() { return Err(gst_loggable_error!(CAT, "Failed to start pad task")); } Ok(()) @@ -771,24 +772,22 @@ impl MccParse { } while let Some(line) = reader.get_line_with_drain(true) { - match parser.parse_line(line, false).map_err(|err| (line, err)) { - Ok(MccLine::Caption(tc, None)) => { - let state = self.state.lock().unwrap(); - let (framerate, drop_frame) = parse_timecode_rate(state.timecode_rate) - .map_err(|_| { - gst_loggable_error!(CAT, "Failed to parse timecode rate") - })?; - last_tc = match parse_timecode(framerate, drop_frame, tc) { - Ok(mut timecode) => { - /* We're looking for the total duration */ - timecode.increment_frame(); - Some(timecode) - } - Err(_) => None, + if let Ok(MccLine::Caption(tc, None)) = + parser.parse_line(line, false).map_err(|err| (line, err)) + { + let state = self.state.lock().unwrap(); + let (framerate, drop_frame) = parse_timecode_rate(state.timecode_rate) + .map_err(|_| gst_loggable_error!(CAT, "Failed to parse timecode rate"))?; + last_tc = match parse_timecode(framerate, drop_frame, tc) { + Ok(mut timecode) => { + /* We're looking for the total duration */ + timecode.increment_frame(); + Some(timecode) } + Err(_) => None, } - _ => { /* We ignore everything else including errors */ } } + /* We ignore everything else including errors */ } if last_tc.is_some() || offset == 0 { diff --git a/gst-plugin-fallbackswitch/src/fallbackswitch.rs b/gst-plugin-fallbackswitch/src/fallbackswitch.rs index 738a438b..8d05884d 100644 --- a/gst-plugin-fallbackswitch/src/fallbackswitch.rs +++ b/gst-plugin-fallbackswitch/src/fallbackswitch.rs @@ -610,7 +610,7 @@ impl AggregatorImpl for FallbackSwitch { // Otherwise if we have a fallback sinkpad and it has a buffer, then the timeout is going // to be its running time. We will then either output the buffer or drop it, depending on // its distance from the last sinkpad time - if let Some(_) = self.sinkpad.peek_buffer() { + if self.sinkpad.peek_buffer().is_some() { gst_debug!(CAT, obj: agg, "Have buffer on sinkpad, immediate timeout"); 0.into() } else if self.sinkpad.is_eos() { @@ -731,7 +731,7 @@ impl AggregatorImpl for FallbackSwitch { audio_info.rate(), audio_info.bpf(), ) - } else if let Some(_) = pad_state.video_info { + } else if pad_state.video_info.is_some() { segment.clip(pts, pts + duration).map(|(start, stop)| { { let buffer = buffer.make_mut(); diff --git a/gst-plugin-lewton/src/lewtondec.rs b/gst-plugin-lewton/src/lewtondec.rs index 473a43f0..9e0b8657 100644 --- a/gst-plugin-lewton/src/lewtondec.rs +++ b/gst-plugin-lewton/src/lewtondec.rs @@ -339,7 +339,7 @@ impl LewtonDec { audio_info = audio_info.positions(to); let mut map = [0; 8]; - if let Err(_) = gst_audio::get_channel_reorder_map(from, to, &mut map[..channels]) { + if gst_audio::get_channel_reorder_map(from, to, &mut map[..channels]).is_err() { gst_error!( CAT, obj: element, diff --git a/gst-plugin-rav1e/src/rav1enc.rs b/gst-plugin-rav1e/src/rav1enc.rs index 22d44ece..2927d521 100644 --- a/gst-plugin-rav1e/src/rav1enc.rs +++ b/gst-plugin-rav1e/src/rav1enc.rs @@ -619,7 +619,7 @@ impl VideoEncoderImpl for Rav1Enc { gst_loggable_error!(CAT, "Failed to create context: {:?}", err) })?) }, - video_info: video_info.clone(), + video_info, }); let output_state = element @@ -638,13 +638,8 @@ impl VideoEncoderImpl for Rav1Enc { let mut state_guard = self.state.borrow_mut(); if let Some(ref mut state) = *state_guard { state.context.flush(); - loop { - match state.context.receive_packet() { - Ok(_) | Err(data::EncoderStatus::Encoded) => { - gst_debug!(CAT, obj: element, "Dropping packet on flush",); - } - _ => break, - } + while let Ok(_) | Err(data::EncoderStatus::Encoded) = state.context.receive_packet() { + gst_debug!(CAT, obj: element, "Dropping packet on flush",); } } diff --git a/gst-plugin-reqwest/src/reqwesthttpsrc.rs b/gst-plugin-reqwest/src/reqwesthttpsrc.rs index ed72d2cc..678deff9 100644 --- a/gst-plugin-reqwest/src/reqwesthttpsrc.rs +++ b/gst-plugin-reqwest/src/reqwesthttpsrc.rs @@ -857,11 +857,8 @@ impl ElementImpl for ReqwestHttpSrc { element: &gst::Element, transition: gst::StateChange, ) -> Result { - match transition { - gst::StateChange::ReadyToNull => { - *self.client.lock().unwrap() = None; - } - _ => (), + if let gst::StateChange::ReadyToNull = transition { + *self.client.lock().unwrap() = None; } self.parent_change_state(element, transition) diff --git a/gst-plugin-rusoto/src/s3sink.rs b/gst-plugin-rusoto/src/s3sink.rs index 89d7b79c..3cd36822 100644 --- a/gst-plugin-rusoto/src/s3sink.rs +++ b/gst-plugin-rusoto/src/s3sink.rs @@ -191,7 +191,7 @@ impl S3Sink { } }; state.completed_parts.push(CompletedPart { - e_tag: output.e_tag.clone(), + e_tag: output.e_tag, part_number: Some(part_number), }); gst_info!(CAT, obj: element, "Uploaded part {}", part_number); @@ -374,7 +374,7 @@ impl S3Sink { fn cancel(&self) { let mut canceller = self.canceller.lock().unwrap(); - if let Some(_) = canceller.take() { + if canceller.take().is_some() { /* We don't do anything, the Sender will be dropped, and that will cause the * Receiver to be cancelled */ } @@ -540,19 +540,16 @@ impl BaseSinkImpl for S3Sink { } fn event(&self, element: &gst_base::BaseSink, event: gst::Event) -> bool { - match event.view() { - gst::EventView::Eos(_) => { - if let Err(error_message) = self.finalize_upload(element) { - gst_error!( - CAT, - obj: element, - "Failed to finalize the upload: {}", - error_message - ); - return false; - } + if let gst::EventView::Eos(_) = event.view() { + if let Err(error_message) = self.finalize_upload(element) { + gst_error!( + CAT, + obj: element, + "Failed to finalize the upload: {}", + error_message + ); + return false; } - _ => (), } BaseSinkImplExt::parent_event(self, element, event) diff --git a/gst-plugin-rusoto/src/s3src.rs b/gst-plugin-rusoto/src/s3src.rs index 3fd1632c..d4ad1b6d 100644 --- a/gst-plugin-rusoto/src/s3src.rs +++ b/gst-plugin-rusoto/src/s3src.rs @@ -67,7 +67,7 @@ impl S3Src { fn cancel(&self) { let mut canceller = self.canceller.lock().unwrap(); - if let Some(_) = canceller.take() { + if canceller.take().is_some() { /* We don't do anything, the Sender will be dropped, and that will cause the * Receiver to be cancelled */ } @@ -394,18 +394,15 @@ impl BaseSrcImpl for S3Src { } fn query(&self, src: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool { - match query.view_mut() { - gst::QueryView::Scheduling(ref mut q) => { - q.set( - gst::SchedulingFlags::SEQUENTIAL | gst::SchedulingFlags::BANDWIDTH_LIMITED, - 1, - -1, - 0, - ); - q.add_scheduling_modes(&[gst::PadMode::Push, gst::PadMode::Pull]); - return true; - } - _ => (), + if let gst::QueryView::Scheduling(ref mut q) = query.view_mut() { + q.set( + gst::SchedulingFlags::SEQUENTIAL | gst::SchedulingFlags::BANDWIDTH_LIMITED, + 1, + -1, + 0, + ); + q.add_scheduling_modes(&[gst::PadMode::Push, gst::PadMode::Pull]); + return true; } BaseSrcImplExt::parent_query(self, src, query) diff --git a/gst-plugin-togglerecord/src/togglerecord.rs b/gst-plugin-togglerecord/src/togglerecord.rs index f6937d0a..fc61cbb1 100644 --- a/gst-plugin-togglerecord/src/togglerecord.rs +++ b/gst-plugin-togglerecord/src/togglerecord.rs @@ -326,7 +326,7 @@ impl HandleData for gst::Buffer { audio_info.rate(), audio_info.bpf(), ) - } else if let Some(_) = state.video_info { + } else if state.video_info.is_some() { segment.clip(pts, stop).map(move |(start, stop)| { { let buffer = self.make_mut(); @@ -1472,9 +1472,9 @@ impl ToggleRecord { }; if pad == &stream.srcpad { - gst::Iterator::from_vec(vec![stream.sinkpad.clone()]) + gst::Iterator::from_vec(vec![stream.sinkpad]) } else { - gst::Iterator::from_vec(vec![stream.srcpad.clone()]) + gst::Iterator::from_vec(vec![stream.srcpad]) } } } diff --git a/gst-plugin-tutorial/src/sinesrc.rs b/gst-plugin-tutorial/src/sinesrc.rs index 402737e4..60d175c0 100644 --- a/gst-plugin-tutorial/src/sinesrc.rs +++ b/gst-plugin-tutorial/src/sinesrc.rs @@ -416,11 +416,8 @@ impl ElementImpl for SineSrc { let basesrc = element.downcast_ref::().unwrap(); // Configure live'ness once here just before starting the source - match transition { - gst::StateChange::ReadyToPaused => { - basesrc.set_live(self.settings.lock().unwrap().is_live); - } - _ => (), + if let gst::StateChange::ReadyToPaused = transition { + basesrc.set_live(self.settings.lock().unwrap().is_live); } // Call the parent class' implementation of ::change_state() diff --git a/gst-plugin-version-helper/src/lib.rs b/gst-plugin-version-helper/src/lib.rs index ce3af7e1..b179dbcb 100644 --- a/gst-plugin-version-helper/src/lib.rs +++ b/gst-plugin-version-helper/src/lib.rs @@ -13,9 +13,7 @@ //! ```rust,ignore //! extern crate gst_plugin_version_helper; //! -//! fn main() { -//! gst_plugin_version_helper::get_info() -//! } +//! gst_plugin_version_helper::get_info(); //! ``` //! //! Inside `lib.rs` of the plugin, the information provided by `get_info` are usable as follows: @@ -101,7 +99,7 @@ pub fn get_info() { let dt = chrono::Utc.timestamp(timestamp, 0); commit_date = dt.format("%Y-%m-%d").to_string() } else if let Ok(release_file) = fs::File::open(release_file) { - let mut cargo_toml = crate_dir.clone(); + let mut cargo_toml = crate_dir; cargo_toml.push("Cargo.toml"); let cargo_toml = fs::File::open(cargo_toml).expect("Can't open Cargo.toml");