summaryrefslogtreecommitdiffstats
path: root/src/errors.rs
diff options
context:
space:
mode:
authorPaul Woolcock <paul@woolcock.us>2018-08-23 13:05:56 -0400
committerPaul Woolcock <paul@woolcock.us>2018-08-23 13:27:32 -0400
commit384d3d2c41e8bb7c1d2a74bc94d4491a509f154d (patch)
tree5bf3fcdf5014bb3022c43b0b8eaa3986888e132c /src/errors.rs
parentce69407e385da77a4fed424802f7bd78d91a7200 (diff)
add toml helpers to data.rs
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 4af0600..893946a 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -2,6 +2,10 @@ use std::{error, fmt, io::Error as IoError};
use json::Error as SerdeError;
use reqwest::{Error as HttpError, StatusCode};
+#[cfg(feature = "toml")]
+use tomlcrate::de::Error as TomlDeError;
+#[cfg(feature = "toml")]
+use tomlcrate::ser::Error as TomlSerError;
use url::ParseError as UrlError;
/// Convience type over `std::result::Result` with `Error` as the error type.
@@ -36,6 +40,12 @@ pub enum Error {
DataMissing,
/// AppBuilder error
MissingField(&'static str),
+ #[cfg(feature = "toml")]
+ /// Error serializing to toml
+ TomlSer(TomlSerError),
+ #[cfg(feature = "toml")]
+ /// Error deserializing from toml
+ TomlDe(TomlDeError),
}
impl fmt::Display for Error {
@@ -65,6 +75,10 @@ impl error::Error for Error {
Error::AccessTokenRequired => "AccessTokenRequired",
Error::DataMissing => "DataMissing",
Error::MissingField(_) => "MissingField",
+ #[cfg(feature = "toml")]
+ Error::TomlSer(ref e) => e.description(),
+ #[cfg(feature = "toml")]
+ Error::TomlDe(ref e) => e.description(),
}
}
}
@@ -79,8 +93,9 @@ pub struct ApiError {
}
macro_rules! from {
- ($($typ:ident, $variant:ident,)*) => {
+ ($($(#[$met:meta])* $typ:ident, $variant:ident,)*) => {
$(
+ $(#[$met])*
impl From<$typ> for Error {
fn from(from: $typ) -> Self {
use Error::*;
@@ -97,4 +112,6 @@ from! {
SerdeError, Serde,
UrlError, Url,
ApiError, Api,
+ #[cfg(feature = "toml")] TomlSerError, TomlSer,
+ #[cfg(feature = "toml")] TomlDeError, TomlDe,
}