From a022bbe260000d327c136af30774211d75795a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 28 Jul 2020 17:00:48 +0300 Subject: [PATCH] Fix some new clippy warnings --- audio/audiofx/src/audioecho.rs | 2 +- audio/csound/src/filter.rs | 12 ++++-------- generic/file/src/file_location.rs | 6 +++--- generic/threadshare/src/runtime/task.rs | 6 +++--- net/rusoto/src/s3url.rs | 4 ++-- tutorial/src/sinesrc.rs | 8 ++------ tutorial/tutorial-2.md | 11 +++++------ utils/fallbackswitch/src/fallbacksrc.rs | 6 +++--- 8 files changed, 23 insertions(+), 32 deletions(-) diff --git a/audio/audiofx/src/audioecho.rs b/audio/audiofx/src/audioecho.rs index 8fc1e759..d2e1aedc 100644 --- a/audio/audiofx/src/audioecho.rs +++ b/audio/audiofx/src/audioecho.rs @@ -290,7 +290,7 @@ impl BaseTransformImpl for AudioEcho { } let info = gst_audio::AudioInfo::from_caps(incaps) - .or_else(|_| Err(gst_loggable_error!(CAT, "Failed to parse input caps")))?; + .map_err(|_| gst_loggable_error!(CAT, "Failed to parse input caps"))?; let max_delay = self.settings.lock().unwrap().max_delay; let size = max_delay * (info.rate() as u64) / gst::SECOND_VAL; let buffer_size = size * (info.channels() as u64); diff --git a/audio/csound/src/filter.rs b/audio/csound/src/filter.rs index d6c56f91..e25d199d 100644 --- a/audio/csound/src/filter.rs +++ b/audio/csound/src/filter.rs @@ -592,19 +592,15 @@ impl BaseTransformImpl for CsoundFilter { ) -> Result<(), gst::LoggableError> { // Flush previous state if self.state.lock().unwrap().is_some() { - self.drain(element).or_else(|e| { - Err(gst_loggable_error!( - CAT, - "Error flusing previous state data {:?}", - e - )) + self.drain(element).map_err(|e| { + gst_loggable_error!(CAT, "Error flusing previous state data {:?}", e) })?; } let in_info = gst_audio::AudioInfo::from_caps(incaps) - .or_else(|_| Err(gst_loggable_error!(CAT, "Failed to parse input caps")))?; + .map_err(|_| gst_loggable_error!(CAT, "Failed to parse input caps"))?; let out_info = gst_audio::AudioInfo::from_caps(outcaps) - .or_else(|_| Err(gst_loggable_error!(CAT, "Failed to parse output caps")))?; + .map_err(|_| gst_loggable_error!(CAT, "Failed to parse output caps"))?; let csound = self.csound.lock().unwrap(); diff --git a/generic/file/src/file_location.rs b/generic/file/src/file_location.rs index 8eba2c01..eca8e579 100644 --- a/generic/file/src/file_location.rs +++ b/generic/file/src/file_location.rs @@ -30,11 +30,11 @@ impl FileLocation { )); } - let path = url.to_file_path().or_else(|_| { - Err(glib::Error::new( + let path = url.to_file_path().map_err(|_| { + glib::Error::new( gst::URIError::BadUri, format!("Unsupported URI {}", uri_str).as_str(), - )) + ) })?; FileLocation::try_from(path) diff --git a/generic/threadshare/src/runtime/task.rs b/generic/threadshare/src/runtime/task.rs index 53ed66e0..777ff688 100644 --- a/generic/threadshare/src/runtime/task.rs +++ b/generic/threadshare/src/runtime/task.rs @@ -338,7 +338,7 @@ impl TaskInner { gst_log!(RUNTIME_CAT, "Pushing {:?}", triggering_evt); - triggering_evt_tx.try_send(triggering_evt).or_else(|err| { + triggering_evt_tx.try_send(triggering_evt).map_err(|err| { let resource_err = if err.is_full() { gst::ResourceError::NoSpaceLeft } else { @@ -346,11 +346,11 @@ impl TaskInner { }; gst_warning!(RUNTIME_CAT, "Unable to send {:?}: {:?}", trigger, err); - Err(TransitionError { + TransitionError { trigger, state: self.state, err_msg: gst_error_msg!(resource_err, ["Unable to send {:?}: {:?}", trigger, err]), - }) + } })?; Ok(ack_rx) diff --git a/net/rusoto/src/s3url.rs b/net/rusoto/src/s3url.rs index 01a41a83..c059f96f 100644 --- a/net/rusoto/src/s3url.rs +++ b/net/rusoto/src/s3url.rs @@ -44,7 +44,7 @@ impl ToString for GstS3Url { } pub fn parse_s3_url(url_str: &str) -> Result { - let url = Url::parse(url_str).or_else(|err| Err(format!("Parse error: {}", err)))?; + let url = Url::parse(url_str).map_err(|err| format!("Parse error: {}", err))?; if url.scheme() != "s3" { return Err(format!("Unsupported URI '{}'", url.scheme())); @@ -55,7 +55,7 @@ pub fn parse_s3_url(url_str: &str) -> Result { } let host = url.host_str().unwrap(); - let region = Region::from_str(host).or_else(|_| Err(format!("Invalid region '{}'", host)))?; + let region = Region::from_str(host).map_err(|_| format!("Invalid region '{}'", host))?; let mut path = url .path_segments() diff --git a/tutorial/src/sinesrc.rs b/tutorial/src/sinesrc.rs index 2c4bad8c..ad183d41 100644 --- a/tutorial/src/sinesrc.rs +++ b/tutorial/src/sinesrc.rs @@ -434,12 +434,8 @@ impl BaseSrcImpl for SineSrc { ) -> Result<(), gst::LoggableError> { use std::f64::consts::PI; - let info = gst_audio::AudioInfo::from_caps(caps).or_else(|_| { - Err(gst_loggable_error!( - CAT, - "Failed to build `AudioInfo` from caps {}", - caps - )) + let info = gst_audio::AudioInfo::from_caps(caps).map_err(|_| { + gst_loggable_error!(CAT, "Failed to build `AudioInfo` from caps {}", caps) })?; gst_debug!(CAT, obj: element, "Configuring for caps {}", caps); diff --git a/tutorial/tutorial-2.md b/tutorial/tutorial-2.md index f1f03f76..16566f35 100644 --- a/tutorial/tutorial-2.md +++ b/tutorial/tutorial-2.md @@ -410,13 +410,12 @@ The first part that we have to implement, just like last time, is caps negotiati First of all, we need to get notified whenever the caps that our source is configured for are changing. This will happen once in the very beginning and then whenever the pipeline topology or state changes and new caps would be more optimal for the new situation. This notification happens via the `BaseTransform::set_caps` virtual method. ```rust - fn set_caps(&self, element: &BaseSrc, caps: &gst::Caps) -> bool { + fn set_caps(&self, element: &BaseSrc, caps: &gst::Caps) -> Result<(), gst::LoggableError> { use std::f64::consts::PI; - let info = match gst_audio::AudioInfo::from_caps(caps) { - None => return false, - Some(info) => info, - }; + let info = gst_audio::AudioInfo::from_caps(caps).map_err(|_| { + gst_loggable_error!(CAT, "Failed to build `AudioInfo` from caps {}", caps) + })?; gst_debug!(CAT, obj: element, "Configuring for caps {}", caps); @@ -457,7 +456,7 @@ First of all, we need to get notified whenever the caps that our source is confi let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build()); - true + Ok(()) } ``` diff --git a/utils/fallbackswitch/src/fallbacksrc.rs b/utils/fallbackswitch/src/fallbacksrc.rs index f2617180..53197983 100644 --- a/utils/fallbackswitch/src/fallbacksrc.rs +++ b/utils/fallbackswitch/src/fallbacksrc.rs @@ -457,7 +457,7 @@ impl ObjectImpl for FallbackSrc { // Called whenever a value of a property is read. It can be called // at any time from any thread. - #[allow(clippy::block_in_if_condition_stmt)] + #[allow(clippy::blocks_in_if_conditions)] fn get_property(&self, _obj: &glib::Object, id: usize) -> Result { let prop = &PROPERTIES[id]; @@ -1984,7 +1984,7 @@ impl FallbackSrc { }); } - #[allow(clippy::block_in_if_condition_stmt)] + #[allow(clippy::blocks_in_if_conditions)] fn schedule_source_restart_timeout( &self, element: &gst::Bin, @@ -2061,7 +2061,7 @@ impl FallbackSrc { state.source_restart_timeout = Some(timeout); } - #[allow(clippy::block_in_if_condition_stmt)] + #[allow(clippy::blocks_in_if_conditions)] fn have_fallback_activated(&self, _element: &gst::Bin, state: &State) -> bool { let mut have_audio = false; let mut have_video = false;