Move From<> impls too

master
Paul Woolcock 6 years ago
parent 3f5c1db430
commit 454d005517
  1. 25
      src/errors.rs
  2. 23
      src/lib.rs

@ -1,7 +1,7 @@
use std::{ use std::{
io,
fmt, fmt,
error error,
io::Error as IoError
}; };
use json::Error as SerdeError; use json::Error as SerdeError;
@ -28,7 +28,7 @@ pub enum Error {
Http(HttpError), Http(HttpError),
/// Wrapper around the `std::io::Error` struct. /// Wrapper around the `std::io::Error` struct.
#[serde(skip_deserializing)] #[serde(skip_deserializing)]
Io(io::Error), Io(IoError),
/// Wrapper around the `url::ParseError` struct. /// Wrapper around the `url::ParseError` struct.
#[serde(skip_deserializing)] #[serde(skip_deserializing)]
Url(UrlError), Url(UrlError),
@ -86,3 +86,22 @@ pub struct ApiError {
pub error_description: Option<String>, pub error_description: Option<String>,
} }
macro_rules! from {
($($typ:ident, $variant:ident,)*) => {
$(
impl From<$typ> for Error {
fn from(from: $typ) -> Self {
use Error::*;
$variant(from)
}
}
)*
}
}
from! {
HttpError, Http,
IoError, Io,
SerdeError, Serde,
UrlError, Url,
}

@ -61,14 +61,10 @@ pub mod prelude {
} }
use std::borrow::Cow; use std::borrow::Cow;
use std::io::Error as IoError;
use std::ops; use std::ops;
use json::Error as SerdeError;
use reqwest::Error as HttpError;
use reqwest::{Client, Response}; use reqwest::{Client, Response};
use reqwest::header::{Authorization, Bearer, Headers}; use reqwest::header::{Authorization, Bearer, Headers};
use url::ParseError as UrlError;
use entities::prelude::*; use entities::prelude::*;
pub use status_builder::StatusBuilder; pub use status_builder::StatusBuilder;
@ -686,25 +682,6 @@ impl ops::Deref for Mastodon {
} }
} }
macro_rules! from {
($($typ:ident, $variant:ident,)*) => {
$(
impl From<$typ> for Error {
fn from(from: $typ) -> Self {
use Error::*;
$variant(from)
}
}
)*
}
}
from! {
HttpError, Http,
IoError, Io,
SerdeError, Serde,
UrlError, Url,
}
// Convert the HTTP response body from JSON. Pass up deserialization errors // Convert the HTTP response body from JSON. Pass up deserialization errors
// transparently. // transparently.

Loading…
Cancel
Save