diff options
author | Joel Gallant <joel@joelgallant.me> | 2020-09-03 12:06:08 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 12:06:08 -0600 |
commit | 436c964037a1833fe6d17eda37e25425af7e9760 (patch) | |
tree | 5e6468c43f2f06fca2a338839a3d7a80e4d67d49 /src/error.rs | |
parent | 2c0b201055be60ec45e258adcc6c4b6e01bcd627 (diff) | |
parent | e84a39949c0c1625c1886b8f718b8165c7a8e831 (diff) |
Merge pull request #134 from eisterman/fix_clippy_warnings
Fix of all the clippy warnings and removing of deprecated Error::description method
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/src/error.rs b/src/error.rs index d7beeaf..b6730e3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -51,7 +51,7 @@ pub enum ConfigError { /// The captured error from attempting to parse the file in its desired format. /// This is the actual error object from the library used for the parsing. - cause: Box<Error + Send + Sync>, + cause: Box<dyn Error + Send + Sync>, }, /// Value could not be converted into the requested type. @@ -76,7 +76,7 @@ pub enum ConfigError { Message(String), /// Unadorned error from a foreign origin. - Foreign(Box<Error + Send + Sync>), + Foreign(Box<dyn Error + Send + Sync>), } impl ConfigError { @@ -88,9 +88,9 @@ impl ConfigError { expected: &'static str, ) -> Self { ConfigError::Type { - origin: origin, - unexpected: unexpected, - expected: expected, + origin, + unexpected, + expected, key: None, } } @@ -105,9 +105,9 @@ impl ConfigError { expected, .. } => ConfigError::Type { - origin: origin, - unexpected: unexpected, - expected: expected, + origin, + unexpected, + expected, key: Some(key.into()), }, @@ -166,7 +166,9 @@ impl fmt::Debug for ConfigError { impl fmt::Display for ConfigError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - ConfigError::Frozen | ConfigError::PathParse(_) => write!(f, "{}", self.description()), + ConfigError::Frozen => write!(f, "configuration is frozen"), + + ConfigError::PathParse(ref kind) => write!(f, "{}", kind.description()), ConfigError::Message(ref s) => write!(f, "{}", s), @@ -208,31 +210,7 @@ impl fmt::Display for ConfigError { } } -impl Error for ConfigError { - fn description(&self) -> &str { - match *self { - ConfigError::Frozen => "configuration is frozen", - ConfigError::NotFound(_) => "configuration property not found", - ConfigError::Type { .. } => "invalid type", - ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => { - cause.description() - } - ConfigError::PathParse(ref kind) => kind.description(), - - _ => "configuration error", - } - } - - fn cause(&self) -> Option<&Error> { - match *self { - ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => { - Some(cause.as_ref()) - } - - _ => None, - } - } -} +impl Error for ConfigError { } impl de::Error for ConfigError { fn custom<T: fmt::Display>(msg: T) -> Self { |