From c42b3daead61f7ae59a2fb2d31be772eeb2205dc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 11 Apr 2019 16:40:12 +0200 Subject: Ditch quick_error because it doesn't support generic parameters --- Cargo.lock | 7 ----- dhall/Cargo.toml | 1 - dhall/src/error.rs | 73 +++++++++++++++++++++++++++++++++------------------- dhall/src/imports.rs | 11 +++----- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0a55ca..781c593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,6 @@ dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "term-painter 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -266,11 +265,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "quick-error" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "quote" version = "0.6.11" @@ -454,7 +448,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum pretty 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f60c0d9f6fc88ecdd245d90c1920ff76a430ab34303fc778d33b1d0a4c3bf6d3" "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" 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 = std::result::Result; -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) { - 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), + 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 for Error { + fn from(err: std::io::Error) -> Error { + Error::IO(err) + } +} +impl From for Error { + fn from(err: dhall_core::ParseError) -> Error { + Error::Parse(err) + } +} +impl From for Error { + fn from(err: crate::binary::DecodeError) -> Error { + Error::Decode(err) + } +} +impl From for Error { + fn from(err: crate::imports::ImportError) -> Error { + Error::Resolve(err) + } +} +impl From> for Error { + fn from(err: crate::typecheck::TypeError) -> 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) {} - UnexpectedImport(import: Import) {} - } +#[derive(Debug)] +pub enum ImportError { + Recursive(Import, Box), + UnexpectedImport(Import), } /// A root from which to resolve relative imports. -- cgit v1.2.3