Verified Commit 53bceb89 authored by Jordan Petridis's avatar Jordan Petridis

Merge branch 'Ophirr33/podcasts-master'

See !82 for more.
parents 04770a1e 5d71ac58
Pipeline #40016 failed with stages
in 34 minutes and 6 seconds
......@@ -91,74 +91,34 @@ pub enum DataError {
EpisodeNotChanged,
}
impl From<RunMigrationsError> for DataError {
fn from(err: RunMigrationsError) -> Self {
DataError::DieselMigrationError(err)
}
}
impl From<diesel::result::Error> for DataError {
fn from(err: diesel::result::Error) -> Self {
DataError::DieselResultError(err)
}
}
impl From<r2d2::Error> for DataError {
fn from(err: r2d2::Error) -> Self {
DataError::R2D2Error(err)
}
}
impl From<r2d2::PoolError> for DataError {
fn from(err: r2d2::PoolError) -> Self {
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)
}
// Maps a type to a variant of the DataError enum
#[macro_export]
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<String> for DataError {
fn from(err: String) -> Self {
DataError::Bail(err)
}
}
easy_from_impl!(
DataError,
RunMigrationsError => DataError::DieselMigrationError,
diesel::result::Error => DataError::DieselResultError,
r2d2::Error => DataError::R2D2Error,
r2d2::PoolError => DataError::R2D2PoolError,
hyper::Error => DataError::HyperError,
http::header::ToStrError => DataError::HttpToStr,
url::ParseError => DataError::UrlError,
native_tls::Error => DataError::TLSError,
io::Error => DataError::IOError,
rss::Error => DataError::RssError,
xml::reader::Error => DataError::XmlReaderError,
String => DataError::Bail
);
......@@ -44,20 +44,9 @@ pub enum DownloadError {
InvalidCachedImageLocation,
}
impl From<reqwest::Error> for DownloadError {
fn from(err: reqwest::Error) -> Self {
DownloadError::RequestError(err)
}
}
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)
}
}
easy_from_impl!(
DownloadError,
reqwest::Error => DownloadError::RequestError,
io::Error => DownloadError::IoError,
DataError => DownloadError::DataError
);
......@@ -56,6 +56,7 @@ extern crate pretty_assertions;
extern crate glob;
extern crate mime_guess;
#[macro_use]
extern crate podcasts_data;
extern crate reqwest;
extern crate tempdir;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment