From bb8072c4d85fd25c1dbe97bfc32646861bf42b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 22 Aug 2016 22:35:16 +0300 Subject: [PATCH] Various cleanups --- src/rsfilesink.rs | 12 ++++++------ src/rsfilesrc.rs | 10 +++++----- src/rshttpsrc.rs | 14 +++++++------- src/utils.rs | 5 +---- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/rsfilesink.rs b/src/rsfilesink.rs index e08c8a23..2912b83a 100644 --- a/src/rsfilesink.rs +++ b/src/rsfilesink.rs @@ -63,7 +63,7 @@ impl FileSink { impl Sink for FileSink { fn set_uri(&self, uri: Option) -> bool { - let ref mut location = self.settings.lock().unwrap().location; + let location = &mut self.settings.lock().unwrap().location; match uri { None => { @@ -87,14 +87,14 @@ impl Sink for FileSink { } fn get_uri(&self) -> Option { - let ref location = self.settings.lock().unwrap().location; + let location = &self.settings.lock().unwrap().location; location.as_ref() .map(|l| Url::from_file_path(l).ok()) .and_then(|i| i) // join() } fn start(&self) -> bool { - let ref location = self.settings.lock().unwrap().location; + let location = &self.settings.lock().unwrap().location; let mut streaming_state = self.streaming_state.lock().unwrap(); if let StreamingState::Started { .. } = *streaming_state { @@ -137,15 +137,15 @@ impl Sink for FileSink { match file.write_all(data) { Ok(_) => { *position += data.len() as u64; - return GstFlowReturn::Ok; + GstFlowReturn::Ok } Err(err) => { println_err!("Failed to write: {}", err); - return GstFlowReturn::Error; + GstFlowReturn::Error } } } else { - return GstFlowReturn::Error; + GstFlowReturn::Error } } } diff --git a/src/rsfilesrc.rs b/src/rsfilesrc.rs index 86cfc08a..917b8df3 100644 --- a/src/rsfilesrc.rs +++ b/src/rsfilesrc.rs @@ -64,7 +64,7 @@ impl FileSrc { impl Source for FileSrc { fn set_uri(&self, uri: Option) -> bool { - let ref mut location = self.settings.lock().unwrap().location; + let location = &mut self.settings.lock().unwrap().location; match uri { None => { @@ -88,7 +88,8 @@ impl Source for FileSrc { } fn get_uri(&self) -> Option { - let ref location = self.settings.lock().unwrap().location; + let location = &self.settings.lock().unwrap().location; + location.as_ref() .map(|l| Url::from_file_path(l).ok()) .and_then(|i| i) // join() @@ -104,15 +105,14 @@ impl Source for FileSrc { if let StreamingState::Started { ref file, .. } = *streaming_state { file.metadata() .ok() - .map(|m| m.len()) - .unwrap_or(u64::MAX) + .map_or(u64::MAX, |m| m.len()) } else { u64::MAX } } fn start(&self) -> bool { - let ref location = self.settings.lock().unwrap().location; + let location = &self.settings.lock().unwrap().location; let mut streaming_state = self.streaming_state.lock().unwrap(); if let StreamingState::Started { .. } = *streaming_state { diff --git a/src/rshttpsrc.rs b/src/rshttpsrc.rs index 9c6f804a..9718d357 100644 --- a/src/rshttpsrc.rs +++ b/src/rshttpsrc.rs @@ -73,7 +73,7 @@ impl HttpSrc { } fn do_request(&self, start: u64, stop: u64) -> StreamingState { - let ref url = self.settings.lock().unwrap().url; + let url = &self.settings.lock().unwrap().url; match *url { None => StreamingState::Stopped, @@ -142,29 +142,29 @@ impl HttpSrc { impl Source for HttpSrc { fn set_uri(&self, uri: Option) -> bool { - let ref mut url = self.settings.lock().unwrap().url; + let url = &mut self.settings.lock().unwrap().url; match uri { None => { *url = None; - return true; + true } Some(uri) => { if uri.scheme() == "http" || uri.scheme() == "https" { *url = Some(uri); - return true; + true } else { *url = None; println_err!("Unsupported URI '{}'", uri.as_str()); - return false; + false } } } } fn get_uri(&self) -> Option { - let ref url = self.settings.lock().unwrap().url; - url.as_ref().map(|u| u.clone()) + let url = &self.settings.lock().unwrap().url; + url.as_ref().cloned() } fn is_seekable(&self) -> bool { diff --git a/src/utils.rs b/src/utils.rs index 886fcf4e..71d4ca8e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -22,11 +22,8 @@ use std::ffi::CString; #[macro_export] macro_rules! println_err( ($($arg:tt)*) => { { - let r = writeln!(&mut ::std::io::stderr(), $($arg)*); + if let Err(_) = writeln!(&mut ::std::io::stderr(), $($arg)*) { // Ignore when writing fails - match r { - Ok(_) => (), - Err(_) => () }; } } );