diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-10-15 17:28:01 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-10-15 17:28:01 -0400 |
commit | 1ead7cd5ecd891598d9b61c0e9e01a2c1c0f27af (patch) | |
tree | de3b4d8c179ed0a2d102165aafa40a31cbfb195c /src/error | |
parent | c0a071f81b2a7a9776dfca313b19ade350c677b2 (diff) |
remove keymapping default code
- just use a big string and parse it at runtime
Diffstat (limited to 'src/error')
-rw-r--r-- | src/error/error_kind.rs | 16 | ||||
-rw-r--r-- | src/error/error_type.rs | 23 |
2 files changed, 29 insertions, 10 deletions
diff --git a/src/error/error_kind.rs b/src/error/error_kind.rs index 679ad32..50fbf16 100644 --- a/src/error/error_kind.rs +++ b/src/error/error_kind.rs @@ -1,6 +1,7 @@ +use std::convert::From; use std::io; -#[derive(Copy, Clone, Debug)] +#[derive(Clone, Debug)] pub enum JoshutoErrorKind { // io related Io(io::ErrorKind), @@ -11,6 +12,7 @@ pub enum JoshutoErrorKind { // parse error ParseError, ClipboardError, + TomlDeError(toml::de::Error), Glob, @@ -20,20 +22,26 @@ pub enum JoshutoErrorKind { UnrecognizedCommand, } -impl std::convert::From<io::ErrorKind> for JoshutoErrorKind { +impl From<io::ErrorKind> for JoshutoErrorKind { fn from(err: io::ErrorKind) -> Self { Self::Io(err) } } -impl std::convert::From<&globset::ErrorKind> for JoshutoErrorKind { +impl From<&globset::ErrorKind> for JoshutoErrorKind { fn from(_: &globset::ErrorKind) -> Self { Self::Glob } } -impl std::convert::From<std::env::VarError> for JoshutoErrorKind { +impl From<std::env::VarError> for JoshutoErrorKind { fn from(_: std::env::VarError) -> Self { Self::EnvVarNotPresent } } + +impl From<toml::de::Error> for JoshutoErrorKind { + fn from(err: toml::de::Error) -> Self { + Self::TomlDeError(err) + } +} diff --git a/src/error/error_type.rs b/src/error/error_type.rs index 9ca849a..d35b808 100644 --- a/src/error/error_type.rs +++ b/src/error/error_type.rs @@ -1,7 +1,9 @@ +use std::convert::From; use std::io; use super::JoshutoErrorKind; +#[derive(Clone, Debug)] pub struct JoshutoError { _kind: JoshutoErrorKind, _cause: String, @@ -13,8 +15,8 @@ impl JoshutoError { Self { _kind, _cause } } - pub fn kind(&self) -> JoshutoErrorKind { - self._kind + pub fn kind(&self) -> &JoshutoErrorKind { + &self._kind } } @@ -24,7 +26,7 @@ impl std::fmt::Display for JoshutoError { } } -impl std::convert::From<io::Error> for JoshutoError { +impl From<io::Error> for JoshutoError { fn from(err: io::Error) -> Self { Self { _kind: JoshutoErrorKind::from(err.kind()), @@ -33,7 +35,7 @@ impl std::convert::From<io::Error> for JoshutoError { } } -impl std::convert::From<globset::Error> for JoshutoError { +impl From<globset::Error> for JoshutoError { fn from(err: globset::Error) -> Self { Self { _kind: JoshutoErrorKind::from(err.kind()), @@ -42,7 +44,7 @@ impl std::convert::From<globset::Error> for JoshutoError { } } -impl std::convert::From<std::env::VarError> for JoshutoError { +impl From<std::env::VarError> for JoshutoError { fn from(err: std::env::VarError) -> Self { Self { _kind: JoshutoErrorKind::from(err), @@ -51,7 +53,7 @@ impl std::convert::From<std::env::VarError> for JoshutoError { } } -impl std::convert::From<trash::Error> for JoshutoError { +impl From<trash::Error> for JoshutoError { fn from(err: trash::Error) -> Self { let err = match err { trash::Error::Unknown => { @@ -75,3 +77,12 @@ impl std::convert::From<trash::Error> for JoshutoError { } } } + +impl From<toml::de::Error> for JoshutoError { + fn from(err: toml::de::Error) -> Self { + Self { + _kind: JoshutoErrorKind::from(err), + _cause: "Failed to parse TOML".to_string(), + } + } +} |