diff options
author | Nadrieril | 2019-04-11 16:40:12 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-11 16:40:12 +0200 |
commit | c42b3daead61f7ae59a2fb2d31be772eeb2205dc (patch) | |
tree | 9c93ad19c7d852a03f468e67ad35a36221d7637a /dhall | |
parent | b694e567392256eb0a429586b2230253d4d80564 (diff) |
Ditch quick_error because it doesn't support generic parameters
Diffstat (limited to 'dhall')
-rw-r--r-- | dhall/Cargo.toml | 1 | ||||
-rw-r--r-- | dhall/src/error.rs | 73 | ||||
-rw-r--r-- | dhall/src/imports.rs | 11 |
3 files changed, 50 insertions, 35 deletions
diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index 7f695d4..0c9b97a 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -13,7 +13,6 @@ bytecount = "0.5.1" itertools = "0.8.0" lalrpop-util = "0.16.3" term-painter = "0.2.3" -quick-error = "1.2.2" serde = { version = "1.0", features = ["derive"] } serde_cbor = "0.9.0" dhall_core = { path = "../dhall_core" } diff --git a/dhall/src/error.rs b/dhall/src/error.rs index cfd6f09..0a02816 100644 --- a/dhall/src/error.rs +++ b/dhall/src/error.rs @@ -1,32 +1,51 @@ -use quick_error::quick_error; - pub type Result<T> = std::result::Result<T, Error>; -quick_error! { - #[derive(Debug)] - pub enum Error { - IO(err: std::io::Error) { - from() - display("{}", err) - } - Parse(err: dhall_core::ParseError) { - from() - display("{}", err) - } - Decode(err: crate::binary::DecodeError) { - from() - display("{:?}", err) - } - Resolve(err: crate::imports::ImportError) { - from() - display("{}", err) - } - Typecheck(err: crate::typecheck::TypeError<dhall_core::X>) { - from() - display("{:?}", err) - } - Deserialize(err: String) { - display("{}", err) +#[derive(Debug)] +pub enum Error { + IO(std::io::Error), + Parse(dhall_core::ParseError), + Decode(crate::binary::DecodeError), + Resolve(crate::imports::ImportError), + Typecheck(crate::typecheck::TypeError<dhall_core::X>), + Deserialize(String), +} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Error::IO(err) => write!(f, "{}", err), + Error::Parse(err) => write!(f, "{}", err), + Error::Decode(err) => write!(f, "{:?}", err), + Error::Resolve(err) => write!(f, "{:?}", err), + Error::Typecheck(err) => write!(f, "{:?}", err), + Error::Deserialize(err) => write!(f, "{}", err), } } } + +impl std::error::Error for Error {} +impl From<std::io::Error> for Error { + fn from(err: std::io::Error) -> Error { + Error::IO(err) + } +} +impl From<dhall_core::ParseError> for Error { + fn from(err: dhall_core::ParseError) -> Error { + Error::Parse(err) + } +} +impl From<crate::binary::DecodeError> for Error { + fn from(err: crate::binary::DecodeError) -> Error { + Error::Decode(err) + } +} +impl From<crate::imports::ImportError> for Error { + fn from(err: crate::imports::ImportError) -> Error { + Error::Resolve(err) + } +} +impl From<crate::typecheck::TypeError<dhall_core::X>> for Error { + fn from(err: crate::typecheck::TypeError<dhall_core::X>) -> Error { + Error::Typecheck(err) + } +} diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 7810c55..e42bfec 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -1,18 +1,15 @@ use crate::error::Error; use crate::expr::*; use dhall_core::*; -use quick_error::quick_error; use std::fs::File; use std::io::Read; use std::path::Path; use std::path::PathBuf; -quick_error! { - #[derive(Debug)] - pub enum ImportError { - Recursive(import: Import, err: Box<Error>) {} - UnexpectedImport(import: Import) {} - } +#[derive(Debug)] +pub enum ImportError { + Recursive(Import, Box<Error>), + UnexpectedImport(Import), } /// A root from which to resolve relative imports. |