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 --- dhall/Cargo.toml | 1 - dhall/src/error.rs | 73 +++++++++++++++++++++++++++++++++------------------- dhall/src/imports.rs | 11 +++----- 3 files changed, 50 insertions(+), 35 deletions(-) (limited to 'dhall') 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