Merge branch 'Ophirr33/podcasts-master'

See !82 for more.
This commit is contained in:
Jordan Petridis 2018-11-07 01:34:06 +02:00
commit 53bceb89cd
No known key found for this signature in database
GPG Key ID: E8523968931763BE
3 changed files with 36 additions and 86 deletions

View File

@ -91,74 +91,34 @@ pub enum DataError {
EpisodeNotChanged, EpisodeNotChanged,
} }
impl From<RunMigrationsError> for DataError { // Maps a type to a variant of the DataError enum
fn from(err: RunMigrationsError) -> Self { #[macro_export]
DataError::DieselMigrationError(err) macro_rules! easy_from_impl {
} ($outer_type:ty, $from:ty => $to:expr) => (
impl From<$from> for $outer_type {
fn from(err: $from) -> Self {
$to(err)
}
}
);
($outer_type:ty, $from:ty => $to:expr, $($f:ty => $t:expr),+) => (
easy_from_impl!($outer_type, $from => $to);
easy_from_impl!($outer_type, $($f => $t),+);
);
} }
impl From<diesel::result::Error> for DataError { easy_from_impl!(
fn from(err: diesel::result::Error) -> Self { DataError,
DataError::DieselResultError(err) RunMigrationsError => DataError::DieselMigrationError,
} diesel::result::Error => DataError::DieselResultError,
} r2d2::Error => DataError::R2D2Error,
r2d2::PoolError => DataError::R2D2PoolError,
impl From<r2d2::Error> for DataError { hyper::Error => DataError::HyperError,
fn from(err: r2d2::Error) -> Self { http::header::ToStrError => DataError::HttpToStr,
DataError::R2D2Error(err) url::ParseError => DataError::UrlError,
} native_tls::Error => DataError::TLSError,
} io::Error => DataError::IOError,
rss::Error => DataError::RssError,
impl From<r2d2::PoolError> for DataError { xml::reader::Error => DataError::XmlReaderError,
fn from(err: r2d2::PoolError) -> Self { String => DataError::Bail
DataError::R2D2PoolError(err) );
}
}
impl From<hyper::Error> for DataError {
fn from(err: hyper::Error) -> Self {
DataError::HyperError(err)
}
}
impl From<http::header::ToStrError> for DataError {
fn from(err: http::header::ToStrError) -> Self {
DataError::HttpToStr(err)
}
}
impl From<url::ParseError> for DataError {
fn from(err: url::ParseError) -> Self {
DataError::UrlError(err)
}
}
impl From<native_tls::Error> for DataError {
fn from(err: native_tls::Error) -> Self {
DataError::TLSError(err)
}
}
impl From<io::Error> for DataError {
fn from(err: io::Error) -> Self {
DataError::IOError(err)
}
}
impl From<rss::Error> for DataError {
fn from(err: rss::Error) -> Self {
DataError::RssError(err)
}
}
impl From<xml::reader::Error> for DataError {
fn from(err: xml::reader::Error) -> Self {
DataError::XmlReaderError(err)
}
}
impl From<String> for DataError {
fn from(err: String) -> Self {
DataError::Bail(err)
}
}

View File

@ -44,20 +44,9 @@ pub enum DownloadError {
InvalidCachedImageLocation, InvalidCachedImageLocation,
} }
impl From<reqwest::Error> for DownloadError { easy_from_impl!(
fn from(err: reqwest::Error) -> Self { DownloadError,
DownloadError::RequestError(err) reqwest::Error => DownloadError::RequestError,
} io::Error => DownloadError::IoError,
} DataError => DownloadError::DataError
);
impl From<io::Error> for DownloadError {
fn from(err: io::Error) -> Self {
DownloadError::IoError(err)
}
}
impl From<DataError> for DownloadError {
fn from(err: DataError) -> Self {
DownloadError::DataError(err)
}
}

View File

@ -56,6 +56,7 @@ extern crate pretty_assertions;
extern crate glob; extern crate glob;
extern crate mime_guess; extern crate mime_guess;
#[macro_use]
extern crate podcasts_data; extern crate podcasts_data;
extern crate reqwest; extern crate reqwest;
extern crate tempdir; extern crate tempdir;