From 69be1ce2fc57c3767c1146dda016ef95d58403b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 22 Dec 2019 09:59:23 +0200 Subject: [PATCH] Fix various new clippy warnings from 1.40 --- examples/src/bin/appsink.rs | 2 +- examples/src/bin/appsrc.rs | 2 +- examples/src/bin/decodebin.rs | 4 +- examples/src/bin/encodebin.rs | 4 +- examples/src/bin/glupload.rs | 2 +- examples/src/bin/gtkvideooverlay.rs | 1 - examples/src/bin/pango-cairo.rs | 4 +- examples/src/bin/rtpfecclient.rs | 2 +- examples/src/bin/rtpfecserver.rs | 11 +++--- examples/src/bin/subclass.rs | 2 +- examples/src/bin/tagsetter.rs | 2 +- examples/src/bin/transmux.rs | 2 +- gstreamer-pbutils/src/encoding_profile.rs | 16 ++++---- gstreamer-video/src/functions.rs | 1 - gstreamer-video/src/video_info.rs | 4 +- gstreamer/src/caps_serde.rs | 6 +-- gstreamer/src/clock.rs | 8 +--- gstreamer/src/date_time.rs | 9 +---- gstreamer/src/date_time_serde.rs | 2 +- gstreamer/src/event.rs | 8 +--- gstreamer/src/format_serde.rs | 2 +- gstreamer/src/log.rs | 2 +- gstreamer/src/object.rs | 2 +- gstreamer/src/segment_serde.rs | 14 ++++--- gstreamer/src/subclass/element.rs | 18 ++++----- gstreamer/src/subclass/pad.rs | 18 ++++----- gstreamer/src/tags.rs | 5 ++- gstreamer/src/tags_serde.rs | 45 ++++++++++++++--------- gstreamer/src/toc_serde.rs | 2 + gstreamer/src/value.rs | 4 +- gstreamer/src/value_serde.rs | 5 ++- 31 files changed, 101 insertions(+), 108 deletions(-) diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index 5a3338584..885536f1a 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -168,7 +168,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index 2e3c39917..4af3b6e7a 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -160,7 +160,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index a735a9417..cc6914ec7 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -281,7 +281,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()), @@ -295,7 +295,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/encodebin.rs b/examples/src/bin/encodebin.rs index 8b20b52d4..a4aff5868 100644 --- a/examples/src/bin/encodebin.rs +++ b/examples/src/bin/encodebin.rs @@ -311,7 +311,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()), @@ -325,7 +325,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index 86c1f5c5e..05a83160b 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -594,7 +594,7 @@ impl App { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index fde59357f..f72bcfb65 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -144,7 +144,6 @@ fn create_ui(app: >k::Application) { // simplifies the code within the callback. What this actually does, however, is creating // a memory leak. let video_overlay = sink - .clone() .dynamic_cast::() .unwrap() .downgrade(); diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index 8c821d77b..64daad592 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -213,7 +213,6 @@ fn create_pipeline() -> Result { }) .unwrap(); - let drawer_clone = drawer.clone(); // Add a signal handler to the overlay's "caps-changed" signal. This could e.g. // be called when the sink that we render to does not support resizing the image // itself - but the user just changed the window-size. The element after the overlay @@ -226,7 +225,6 @@ fn create_pipeline() -> Result { let _overlay = args[0].get::().unwrap().unwrap(); let caps = args[1].get::().unwrap().unwrap(); - let drawer = &drawer_clone; let mut drawer = drawer.lock().unwrap(); drawer.info = Some(gst_video::VideoInfo::from_caps(&caps).unwrap()); @@ -257,7 +255,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/rtpfecclient.rs b/examples/src/bin/rtpfecclient.rs index 60d3acf89..b1ca759f6 100644 --- a/examples/src/bin/rtpfecclient.rs +++ b/examples/src/bin/rtpfecclient.rs @@ -275,7 +275,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/rtpfecserver.rs b/examples/src/bin/rtpfecserver.rs index ae9d97382..a5622f181 100644 --- a/examples/src/bin/rtpfecserver.rs +++ b/examples/src/bin/rtpfecserver.rs @@ -146,9 +146,8 @@ fn example_main() -> Result<(), Error> { let sinkpad = get_static_pad(&sink, "sink")?; srcpad.link(&sinkpad)?; - let convclone = conv.clone(); - src.connect_pad_added(move |decodebin, src_pad| { - match connect_decodebin_pad(&src_pad, &convclone) { + src.connect_pad_added( + move |decodebin, src_pad| match connect_decodebin_pad(&src_pad, &conv) { Ok(_) => (), Err(err) => { gst_element_error!( @@ -158,8 +157,8 @@ fn example_main() -> Result<(), Error> { ["{}", err] ); } - } - }); + }, + ); let video_caps = gst::Caps::new_simple("video/x-raw", &[]); @@ -199,7 +198,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index c9ae35a5e..ec49b2541 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -385,7 +385,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/tagsetter.rs b/examples/src/bin/tagsetter.rs index 60190a122..0904ef453 100644 --- a/examples/src/bin/tagsetter.rs +++ b/examples/src/bin/tagsetter.rs @@ -109,7 +109,7 @@ fn example_main() -> Result<(), Error> { .unwrap_or_else(|| "None".into()) .to_string(), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/examples/src/bin/transmux.rs b/examples/src/bin/transmux.rs index 57f1919f2..e470e12ce 100644 --- a/examples/src/bin/transmux.rs +++ b/examples/src/bin/transmux.rs @@ -175,7 +175,7 @@ fn example_main() -> Result<(), Error> { .map(|s| String::from(s.get_path_string())) .unwrap_or_else(|| String::from("None")), error: err.get_error().description().into(), - debug: Some(err.get_debug().unwrap().to_string()), + debug: err.get_debug(), cause: err.get_error(), } .into()); diff --git a/gstreamer-pbutils/src/encoding_profile.rs b/gstreamer-pbutils/src/encoding_profile.rs index 0ea7a1b88..8ce2300e9 100644 --- a/gstreamer-pbutils/src/encoding_profile.rs +++ b/gstreamer-pbutils/src/encoding_profile.rs @@ -488,19 +488,19 @@ mod tests { use auto::EncodingVideoProfile; use gst; - const AUDIO_PROFILE_NAME: &'static str = "audio-profile"; - const AUDIO_PROFILE_DESCRIPTION: &'static str = "audio-profile-description"; - const PRESET: &'static str = "preset"; - const PRESET_NAME: &'static str = "preset-name"; + const AUDIO_PROFILE_NAME: &str = "audio-profile"; + const AUDIO_PROFILE_DESCRIPTION: &str = "audio-profile-description"; + const PRESET: &str = "preset"; + const PRESET_NAME: &str = "preset-name"; const PRESENCE: u32 = 5; const ALLOW_DYNAMIC_OUTPUT: bool = false; const ENABLED: bool = false; - const VIDEO_PROFILE_NAME: &'static str = "video-profile"; - const VIDEO_PROFILE_DESCRIPTION: &'static str = "video-profile-description"; + const VIDEO_PROFILE_NAME: &str = "video-profile"; + const VIDEO_PROFILE_DESCRIPTION: &str = "video-profile-description"; - const CONTAINER_PROFILE_NAME: &'static str = "container-profile"; - const CONTAINER_PROFILE_DESCRIPTION: &'static str = "container-profile-description"; + const CONTAINER_PROFILE_NAME: &str = "container-profile"; + const CONTAINER_PROFILE_DESCRIPTION: &str = "container-profile-description"; // Video profile exclusive attributes const PASS: u32 = 8; diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index fa17bb0fd..987b2ce3f 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -156,7 +156,6 @@ mod tests { l.run(); let res = res_store.lock().unwrap().take().unwrap(); - assert!(res.is_ok(), "Error {}", res.unwrap_err()); let res = res.unwrap(); let converted_out_caps = res.get_caps().unwrap(); diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 88b79a5e0..c5814c4c5 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -973,13 +973,13 @@ mod tests { .expect("Failed to create VideoInfo"); assert_eq!(info.stride(), [1920, 1920]); - assert_eq!(info.offset(), [0, 2073600]); + assert_eq!(info.offset(), [0, 2_073_600]); let mut align = ::VideoAlignment::new(0, 0, 0, 8, &[0; VIDEO_MAX_PLANES]); assert!(info.align(&mut align)); assert_eq!(info.stride(), [1928, 1928]); - assert_eq!(info.offset(), [0, 2082240]); + assert_eq!(info.offset(), [0, 2_082_240]); } #[cfg(any(feature = "v1_12", feature = "dox"))] diff --git a/gstreamer/src/caps_serde.rs b/gstreamer/src/caps_serde.rs index 09a9113e6..0596a6467 100644 --- a/gstreamer/src/caps_serde.rs +++ b/gstreamer/src/caps_serde.rs @@ -247,7 +247,7 @@ mod tests { let mut pretty_config = ron::ser::PrettyConfig::default(); pretty_config.new_line = "".to_string(); - let res = ron::ser::to_string_pretty(&caps, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&caps, pretty_config); assert_eq!( Ok(concat!( "Some([", @@ -279,7 +279,7 @@ mod tests { let mut pretty_config = ron::ser::PrettyConfig::default(); pretty_config.new_line = "".to_string(); - let res = ron::ser::to_string_pretty(&caps, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&caps, pretty_config); assert_eq!( Ok(concat!( "Some([", @@ -339,7 +339,7 @@ mod tests { assert_eq!(Ok("Any".to_owned()), res); let caps_empty = Caps::new_empty(); - let res = ron::ser::to_string_pretty(&caps_empty, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&caps_empty, pretty_config); assert_eq!(Ok("Empty".to_owned()), res); } diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index ed17be595..1b7755585 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -106,13 +106,7 @@ impl ClockId { unsafe { let res = gst_sys::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0); - if res < 0 { - cmp::Ordering::Less - } else if res > 0 { - cmp::Ordering::Greater - } else { - cmp::Ordering::Equal - } + res.cmp(&0) } } diff --git a/gstreamer/src/date_time.rs b/gstreamer/src/date_time.rs index aabc2a5e0..0e66d339c 100644 --- a/gstreamer/src/date_time.rs +++ b/gstreamer/src/date_time.rs @@ -87,13 +87,7 @@ impl cmp::PartialOrd for DateTime { fn partial_cmp(&self, other: &Self) -> Option { #[inline] fn get_cmp(delta: i32) -> Option { - Some(if delta < 0 { - cmp::Ordering::Less - } else if delta == 0 { - cmp::Ordering::Equal - } else { - cmp::Ordering::Greater - }) + Some(delta.cmp(&0)) } if !(self.has_year() && other.has_year()) { @@ -239,6 +233,7 @@ impl fmt::Display for DateTime { mod tests { use super::*; + #[allow(clippy::cognitive_complexity)] #[test] fn test_to_utc() { ::init().unwrap(); diff --git a/gstreamer/src/date_time_serde.rs b/gstreamer/src/date_time_serde.rs index aa2ac5a33..690f01a8c 100644 --- a/gstreamer/src/date_time_serde.rs +++ b/gstreamer/src/date_time_serde.rs @@ -197,7 +197,7 @@ mod tests { assert_eq!(Ok("YM(2018, 5)".to_owned()), res); let datetime = DateTime::new_y(2018); - let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&datetime, pretty_config); assert_eq!(Ok("Y(2018)".to_owned()), res); } diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index 2ee4aeceb..d0ed43130 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -68,13 +68,7 @@ impl cmp::Ord for Seqnum { fn cmp(&self, other: &Seqnum) -> cmp::Ordering { unsafe { let ret = gst_sys::gst_util_seqnum_compare(self.0, other.0); - if ret < 0 { - cmp::Ordering::Less - } else if ret > 0 { - cmp::Ordering::Greater - } else { - cmp::Ordering::Equal - } + ret.cmp(&0) } } } diff --git a/gstreamer/src/format_serde.rs b/gstreamer/src/format_serde.rs index ff8850f50..430fc8b92 100644 --- a/gstreamer/src/format_serde.rs +++ b/gstreamer/src/format_serde.rs @@ -125,7 +125,7 @@ mod tests { assert_eq!("{\"Other\":[\"Percent\",42]}".to_owned(), res); let value = GenericFormattedValue::Other(Format::__Unknown(7), 42); - let res = ron::ser::to_string_pretty(&value, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&value, pretty_config); assert_eq!(Ok("Other(__Unknown(7), 42)".to_owned()), res); let res = serde_json::to_string(&value).unwrap(); assert_eq!("{\"Other\":[{\"__Unknown\":7},42]}".to_owned(), res); diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index 594b634d0..a53adafd2 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -474,7 +474,7 @@ mod tests { let log_fn = debug_add_log_function(handler); gst_info!(cat, obj: &obj, "meh"); - let _ = receiver.recv().unwrap(); + receiver.recv().unwrap(); debug_remove_log_function(log_fn); diff --git a/gstreamer/src/object.rs b/gstreamer/src/object.rs index b053dc8b0..76af69512 100644 --- a/gstreamer/src/object.rs +++ b/gstreamer/src/object.rs @@ -117,7 +117,7 @@ mod tests { let notify = Arc::new(Mutex::new(None)); let notify_clone = notify.clone(); bin.connect_deep_notify(None, move |_, id, prop| { - *notify_clone.lock().unwrap() = Some((id.clone(), String::from(prop.get_name()))); + *notify_clone.lock().unwrap() = Some((id.clone(), prop.get_name())); }); identity.set_property("silent", &false).unwrap(); diff --git a/gstreamer/src/segment_serde.rs b/gstreamer/src/segment_serde.rs index fcaf22580..8ea85e700 100644 --- a/gstreamer/src/segment_serde.rs +++ b/gstreamer/src/segment_serde.rs @@ -191,8 +191,8 @@ mod tests { segment.get_flags(), SegmentFlags::RESET | SegmentFlags::SEGMENT ); - assert_eq!(segment.get_rate(), 1f64); - assert_eq!(segment.get_applied_rate(), 0.9f64); + assert!((segment.get_rate() - 1f64).abs() < std::f64::EPSILON); + assert!((segment.get_applied_rate() - 0.9f64).abs() < std::f64::EPSILON); assert_eq!(segment.get_format(), Format::Time); assert_eq!( segment.get_base(), @@ -254,8 +254,8 @@ mod tests { fmt_seg.get_flags(), SegmentFlags::RESET | SegmentFlags::SEGMENT ); - assert_eq!(fmt_seg.get_rate(), 1f64); - assert_eq!(fmt_seg.get_applied_rate(), 0.9f64); + assert!((fmt_seg.get_rate() - 1f64).abs() < std::f64::EPSILON); + assert!((fmt_seg.get_applied_rate() - 0.9f64).abs() < std::f64::EPSILON); assert_eq!(fmt_seg.get_format(), Format::Time); assert_eq!(fmt_seg.get_base(), ClockTime::from_nseconds(123)); assert_eq!(fmt_seg.get_offset(), ClockTime::from_nseconds(42)); @@ -286,8 +286,10 @@ mod tests { let segment_de: Segment = ron::de::from_str(segment_se.as_str()).unwrap(); assert_eq!(segment_de.get_flags(), segment.get_flags()); - assert_eq!(segment_de.get_rate(), segment.get_rate()); - assert_eq!(segment_de.get_applied_rate(), segment.get_applied_rate()); + assert!((segment_de.get_rate() - segment.get_rate()).abs() < std::f64::EPSILON); + assert!( + (segment_de.get_applied_rate() - segment.get_applied_rate()).abs() < std::f64::EPSILON + ); assert_eq!(segment_de.get_format(), segment.get_format()); assert_eq!(segment_de.get_base(), segment.get_base()); assert_eq!(segment_de.get_offset(), segment.get_offset()); diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index a4e4b874f..1b7d683b4 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -523,13 +523,13 @@ mod tests { use super::*; use glib; use glib::subclass; - use std::sync::Mutex; + use std::sync::atomic; struct TestElement { srcpad: ::Pad, sinkpad: ::Pad, - n_buffers: Mutex, - reached_playing: Mutex, + n_buffers: atomic::AtomicU32, + reached_playing: atomic::AtomicBool, } impl TestElement { @@ -578,7 +578,7 @@ mod tests { _element: &::Element, buffer: ::Buffer, ) -> Result<::FlowSuccess, ::FlowError> { - *self.n_buffers.lock().unwrap() += 1; + self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst); self.srcpad.push(buffer) } @@ -616,8 +616,8 @@ mod tests { TestElement::set_pad_functions(&sinkpad, &srcpad); Self { - n_buffers: Mutex::new(0), - reached_playing: Mutex::new(false), + n_buffers: atomic::AtomicU32::new(0), + reached_playing: atomic::AtomicBool::new(false), srcpad, sinkpad, } @@ -665,7 +665,7 @@ mod tests { let res = self.parent_change_state(element, transition)?; if transition == ::StateChange::PausedToPlaying { - *self.reached_playing.lock().unwrap() = true; + self.reached_playing.store(true, atomic::Ordering::SeqCst); } Ok(res) @@ -706,7 +706,7 @@ mod tests { pipeline.set_state(::State::Null).unwrap(); let imp = TestElement::from_instance(&element); - assert_eq!(*imp.n_buffers.lock().unwrap(), 100); - assert_eq!(*imp.reached_playing.lock().unwrap(), true); + assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100); + assert_eq!(imp.reached_playing.load(atomic::Ordering::SeqCst), true); } } diff --git a/gstreamer/src/subclass/pad.rs b/gstreamer/src/subclass/pad.rs index 81d3a822e..dd15c0f91 100644 --- a/gstreamer/src/subclass/pad.rs +++ b/gstreamer/src/subclass/pad.rs @@ -102,11 +102,11 @@ mod tests { use crate::prelude::*; use glib; use glib::subclass; - use std::sync::Mutex; + use std::sync::atomic; struct TestPad { - linked: Mutex, - unlinked: Mutex, + linked: atomic::AtomicBool, + unlinked: atomic::AtomicBool, } impl ObjectSubclass for TestPad { @@ -119,8 +119,8 @@ mod tests { fn new() -> Self { Self { - linked: Mutex::new(false), - unlinked: Mutex::new(false), + linked: atomic::AtomicBool::new(false), + unlinked: atomic::AtomicBool::new(false), } } } @@ -131,12 +131,12 @@ mod tests { impl PadImpl for TestPad { fn linked(&self, pad: &Pad, peer: &Pad) { - *self.linked.lock().unwrap() = true; + self.linked.store(true, atomic::Ordering::SeqCst); self.parent_linked(pad, peer) } fn unlinked(&self, pad: &Pad, peer: &Pad) { - *self.unlinked.lock().unwrap() = true; + self.unlinked.store(true, atomic::Ordering::SeqCst); self.parent_unlinked(pad, peer) } } @@ -160,7 +160,7 @@ mod tests { pad.unlink(&otherpad).unwrap(); let imp = TestPad::from_instance(&pad); - assert!(*imp.linked.lock().unwrap()); - assert!(*imp.unlinked.lock().unwrap()); + assert!(imp.linked.load(atomic::Ordering::SeqCst)); + assert!(imp.unlinked.load(atomic::Ordering::SeqCst)); } } diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index 03cfde1ca..dcf18a699 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -893,7 +893,7 @@ mod tests { { let tags = tags.get_mut().unwrap(); tags.add::(&"some title", TagMergeMode::Append); - tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); + tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); } assert_eq!( tags.to_string(), @@ -910,7 +910,7 @@ mod tests { { let tags = tags.get_mut().unwrap(); tags.add::<Title>(&"some title", TagMergeMode::Append); - tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); + tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); } assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title")); @@ -939,6 +939,7 @@ mod tests { } #[test] + #[allow(clippy::cognitive_complexity)] fn test_generic() { ::init().unwrap(); diff --git a/gstreamer/src/tags_serde.rs b/gstreamer/src/tags_serde.rs index 3510a27c1..eb61514dd 100644 --- a/gstreamer/src/tags_serde.rs +++ b/gstreamer/src/tags_serde.rs @@ -17,6 +17,7 @@ use serde::ser; use serde::ser::{Serialize, SerializeSeq, SerializeStruct, SerializeTuple, Serializer}; use std::cell::RefCell; +use std::cmp; use std::fmt; use std::rc::Rc; @@ -123,18 +124,20 @@ struct TagListSer<'a>(&'a TagListRef); impl<'a> Serialize for TagListSer<'a> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { let tag_count = self.0.n_tags(); - if tag_count > 0 { - let mut seq = serializer.serialize_seq(Some(tag_count as usize))?; - let tag_list_iter = self.0.iter_generic(); - for (tag_name, tag_iter) in tag_list_iter { - seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?; + match tag_count.cmp(&0) { + cmp::Ordering::Greater => { + let mut seq = serializer.serialize_seq(Some(tag_count as usize))?; + let tag_list_iter = self.0.iter_generic(); + for (tag_name, tag_iter) in tag_list_iter { + seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?; + } + seq.end() } - seq.end() - } else if tag_count == 0 { - let seq = serializer.serialize_seq(None)?; - seq.end() - } else { - Err(ser::Error::custom("tag count < 0")) + cmp::Ordering::Equal => { + let seq = serializer.serialize_seq(None)?; + seq.end() + } + cmp::Ordering::Less => Err(ser::Error::custom("tag count < 0")), } } } @@ -337,7 +340,7 @@ mod tests { let tags = tags.get_mut().unwrap(); tags.add::<Title>(&"a title", TagMergeMode::Append); // String tags.add::<Title>(&"another title", TagMergeMode::Append); // String - tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); // u64 + tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64 tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32 tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64 tags.add::<Date>( @@ -485,7 +488,9 @@ mod tests { ::SECOND * 120 ); assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000); - assert_eq!(tags.get_index::<TrackGain>(0).unwrap().get_some(), 1f64); + assert!( + (tags.get_index::<TrackGain>(0).unwrap().get_some() - 1f64).abs() < std::f64::EPSILON + ); assert_eq!( tags.get_index::<Date>(0).unwrap().get().unwrap(), glib::Date::new_dmy(28, glib::DateMonth::May, 2018) @@ -524,7 +529,9 @@ mod tests { Some("another title") ); assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000); - assert_eq!(tags.get_index::<TrackGain>(0).unwrap().get_some(), 1f64); + assert!( + (tags.get_index::<TrackGain>(0).unwrap().get_some() - 1f64).abs() < std::f64::EPSILON + ); assert_eq!( tags.get_index::<Date>(0).unwrap().get().unwrap(), glib::Date::new_dmy(28, glib::DateMonth::May, 2018) @@ -552,7 +559,7 @@ mod tests { tags.set_scope(TagScope::Global); tags.add::<Title>(&"a title", TagMergeMode::Append); // String tags.add::<Title>(&"another title", TagMergeMode::Append); // String - tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); // u64 + tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64 tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32 tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64 tags.add::<Date>( @@ -593,9 +600,11 @@ mod tests { tags_de.get_index::<Bitrate>(0).unwrap().get_some(), tags.get_index::<Bitrate>(0).unwrap().get_some(), ); - assert_eq!( - tags_de.get_index::<TrackGain>(0).unwrap().get_some(), - tags.get_index::<TrackGain>(0).unwrap().get_some(), + assert!( + (tags_de.get_index::<TrackGain>(0).unwrap().get_some() + - tags.get_index::<TrackGain>(0).unwrap().get_some()) + .abs() + < std::f64::EPSILON ); assert_eq!( tags_de.get_index::<Date>(0).unwrap().get(), diff --git a/gstreamer/src/toc_serde.rs b/gstreamer/src/toc_serde.rs index 4d080d436..da525b29f 100644 --- a/gstreamer/src/toc_serde.rs +++ b/gstreamer/src/toc_serde.rs @@ -283,6 +283,7 @@ mod tests { ); } + #[allow(clippy::cognitive_complexity)] #[test] fn test_deserialize() { use tags::Title; @@ -417,6 +418,7 @@ mod tests { assert_eq!(0, chapter2.get_sub_entries().len()); } + #[allow(clippy::cognitive_complexity)] #[test] fn test_serde_roundtrip() { ::init().unwrap(); diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index 2c40d3402..d9e436b68 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -913,9 +913,9 @@ mod tests { let f1 = ::Fraction::new(1, 2); let f2 = ::Fraction::new(2, 3); let mut f3 = f1 * f2; - let f4 = f1 * &f2; + let f4 = f1 * f2; f3 *= f2; - f3 *= &f4; + f3 *= f4; assert_eq!(f3, ::Fraction::new(2, 27)); } diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index 9aa17e61c..31b742797 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -348,7 +348,7 @@ mod tests { // Bitmask let bitmask = Bitmask::new(1024 + 128 + 32); - let res = ron::ser::to_string_pretty(&bitmask, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&bitmask, pretty_config); assert_eq!(Ok("(1184)".to_owned()), res); let res = serde_json::to_string(&bitmask).unwrap(); @@ -448,7 +448,7 @@ mod tests { &send_value_date_time_none, ]); - let res = ron::ser::to_string_pretty(&list, pretty_config.clone()); + let res = ron::ser::to_string_pretty(&list, pretty_config); assert_eq!( Ok(concat!( r#"["#, @@ -555,6 +555,7 @@ mod tests { assert_eq!(bitmask_de, bitmask); } + #[allow(clippy::cognitive_complexity)] #[test] fn test_deserialize_collections() { ::init().unwrap();