Use the Into trait instead of custom into_*() functions

This commit is contained in:
Sebastian Dröge 2017-12-20 20:13:31 +02:00
parent 80a2c5033f
commit 07ce2d64b8
4 changed files with 30 additions and 16 deletions

View file

@ -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();
}
}
}

View file

@ -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()
}
}
}

View file

@ -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()
}
}
}

View file

@ -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
}
}
pub fn into_error(self) -> glib::Error {
impl Into<glib::Error> for UriError {
fn into(self) -> glib::Error {
(&self).into()
}
}
impl<'a> Into<glib::Error> for &'a UriError {
fn into(self) -> glib::Error {
glib::Error::new(self.error, &self.message)
}
}