From 454d0055174f0956c5ef49f84f0b364c0bea4a3e Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Tue, 21 Aug 2018 17:10:44 -0400 Subject: [PATCH] Move From<> impls too --- src/errors.rs | 25 ++++++++++++++++++++++--- src/lib.rs | 23 ----------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 0043c74..efc722c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,7 +1,7 @@ use std::{ - io, fmt, - error + error, + io::Error as IoError }; use json::Error as SerdeError; @@ -28,7 +28,7 @@ pub enum Error { Http(HttpError), /// Wrapper around the `std::io::Error` struct. #[serde(skip_deserializing)] - Io(io::Error), + Io(IoError), /// Wrapper around the `url::ParseError` struct. #[serde(skip_deserializing)] Url(UrlError), @@ -86,3 +86,22 @@ pub struct ApiError { pub error_description: Option, } +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, +} diff --git a/src/lib.rs b/src/lib.rs index 0fb1126..3e2cad6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,14 +61,10 @@ pub mod prelude { } use std::borrow::Cow; -use std::io::Error as IoError; use std::ops; -use json::Error as SerdeError; -use reqwest::Error as HttpError; use reqwest::{Client, Response}; use reqwest::header::{Authorization, Bearer, Headers}; -use url::ParseError as UrlError; use entities::prelude::*; 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 // transparently.