From 2d4e72aa2e5354dda808ffd16edcaa84cb9c5fbd Mon Sep 17 00:00:00 2001 From: Robert Horswell Date: Wed, 26 Aug 2020 19:28:23 +0100 Subject: [PATCH] Remove thiserror crate Manually implement `std::error::Error` and `std::fmt::Display` for the `Error` enum --- Cargo.toml | 1 - src/error.rs | 23 ++++++++++++++++------- src/lib.rs | 1 - 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 20f06bf..c7ea10a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ keywords = ["which", "which-rs", "unix", "command"] [dependencies] libc = "0.2.65" -thiserror = "1.0" [dev-dependencies] tempdir = "0.3.7" diff --git a/src/error.rs b/src/error.rs index 708c884..6d800a6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,17 +1,26 @@ -use thiserror; +use std::fmt; pub type Result = std::result::Result; -#[derive(thiserror::Error, Copy, Clone, Eq, PartialEq, Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Error { - #[error("bad absolute path")] BadAbsolutePath, - #[error("bad relative path")] BadRelativePath, - #[error("cannot find binary path")] CannotFindBinaryPath, - #[error("cannot get current directory")] CannotGetCurrentDir, - #[error("cannot canonicalize path")] CannotCanonicalize, } + +impl std::error::Error for Error {} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::BadAbsolutePath => write!(f, "bad absolute path"), + Error::BadRelativePath => write!(f, "bad relative path"), + Error::CannotFindBinaryPath => write!(f, "cannot find binary path"), + Error::CannotGetCurrentDir => write!(f, "cannot get current directory"), + Error::CannotCanonicalize => write!(f, "cannot canonicalize path"), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index a4c0c45..f6b0180 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,6 @@ //! ``` extern crate libc; -extern crate thiserror; mod checker; mod error;