diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2017-12-20 21:13:31 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-12-20 21:13:31 +0300 |
commit | 07ce2d64b8c5f606a3bd95d2a3943931d14cf41b (patch) | |
tree | 326f6a686dc7c5fcad7e7152d9c4c591168f6cca | |
parent | 80a2c5033f258154226e7f619b72c838cc69f6a2 (diff) |
Use the Into trait instead of custom into_*() functions
-rw-r--r-- | gst-plugin-simple/src/demuxer.rs | 4 | ||||
-rw-r--r-- | gst-plugin-simple/src/sink.rs | 8 | ||||
-rw-r--r-- | gst-plugin-simple/src/source.rs | 8 | ||||
-rw-r--r-- | gst-plugin/src/error.rs | 26 |
4 files changed, 30 insertions, 16 deletions
diff --git a/gst-plugin-simple/src/demuxer.rs b/gst-plugin-simple/src/demuxer.rs index b4e6d4092..4ae8c5aaa 100644 --- a/gst-plugin-simple/src/demuxer.rs +++ b/gst-plugin-simple/src/demuxer.rs @@ -405,7 +405,7 @@ impl Demuxer { } _ => (), } - return flow_error.to_native(); + return flow_error.into(); } } }; @@ -465,7 +465,7 @@ impl Demuxer { } _ => (), } - return flow_error.to_native(); + return flow_error.into(); } } } diff --git a/gst-plugin-simple/src/sink.rs b/gst-plugin-simple/src/sink.rs index 8cbc7335b..ceabefd6e 100644 --- a/gst-plugin-simple/src/sink.rs +++ b/gst-plugin-simple/src/sink.rs @@ -109,7 +109,7 @@ impl Sink { if uri_storage.1 { return Err( - UriError::new(gst::URIError::BadState, "Already started".to_string()).into_error(), + UriError::new(gst::URIError::BadState, "Already started".to_string()).into(), ); } @@ -118,14 +118,14 @@ impl Sink { if let Some(uri_str) = uri_str { match Url::parse(uri_str.as_str()) { Ok(uri) => { - try!((self.uri_validator)(&uri).map_err(|e| e.into_error())); + try!((self.uri_validator)(&uri).map_err(|e| e.into())); uri_storage.0 = Some(uri); Ok(()) } Err(err) => Err(UriError::new( gst::URIError::BadUri, format!("Failed to parse URI '{}': {}", uri_str, err), - ).into_error()), + ).into()), } } else { Ok(()) @@ -228,7 +228,7 @@ impl BaseSinkImpl<BaseSink> for Sink { } _ => (), } - flow_error.to_native() + flow_error.into() } } } diff --git a/gst-plugin-simple/src/source.rs b/gst-plugin-simple/src/source.rs index 20124228c..fa622941a 100644 --- a/gst-plugin-simple/src/source.rs +++ b/gst-plugin-simple/src/source.rs @@ -128,7 +128,7 @@ impl Source { if uri_storage.1 { return Err( - UriError::new(gst::URIError::BadState, "Already started".to_string()).into_error(), + UriError::new(gst::URIError::BadState, "Already started".to_string()).into(), ); } @@ -137,14 +137,14 @@ impl Source { if let Some(uri_str) = uri_str { match Url::parse(uri_str.as_str()) { Ok(uri) => { - try!((self.uri_validator)(&uri).map_err(|e| e.into_error())); + try!((self.uri_validator)(&uri).map_err(|e| e.into())); uri_storage.0 = Some(uri); Ok(()) } Err(err) => Err(UriError::new( gst::URIError::BadUri, format!("Failed to parse URI '{}': {}", uri_str, err), - ).into_error()), + ).into()), } } else { Ok(()) @@ -275,7 +275,7 @@ impl BaseSrcImpl<BaseSrc> for Source { } _ => (), } - flow_error.to_native() + flow_error.into() } } } diff --git a/gst-plugin/src/error.rs b/gst-plugin/src/error.rs index d65299160..5bdb9a640 100644 --- a/gst-plugin/src/error.rs +++ b/gst-plugin/src/error.rs @@ -18,7 +18,7 @@ use glib::translate::ToGlibPtr; use gst; use gst::prelude::*; -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum FlowError { Flushing, Eos, @@ -26,8 +26,14 @@ pub enum FlowError { Error(gst::ErrorMessage), } -impl FlowError { - pub fn to_native(&self) -> gst::FlowReturn { +impl Into<gst::FlowReturn> for FlowError { + fn into(self) -> gst::FlowReturn { + (&self).into() + } +} + +impl<'a> Into<gst::FlowReturn> for &'a FlowError { + fn into(self) -> gst::FlowReturn { match *self { FlowError::Flushing => gst::FlowReturn::Flushing, FlowError::Eos => gst::FlowReturn::Eos, @@ -67,10 +73,10 @@ pub struct UriError { } impl UriError { - pub fn new(error: gst::URIError, message: String) -> UriError { + pub fn new<T: Into<String>>(error: gst::URIError, message: T) -> UriError { UriError { error: error, - message: message, + message: message.into(), } } @@ -81,8 +87,16 @@ impl UriError { pub fn error(&self) -> gst::URIError { self.error } +} + +impl Into<glib::Error> for UriError { + fn into(self) -> glib::Error { + (&self).into() + } +} - pub fn into_error(self) -> glib::Error { +impl<'a> Into<glib::Error> for &'a UriError { + fn into(self) -> glib::Error { glib::Error::new(self.error, &self.message) } } |