From 57fb2610ad274dff1d2f2e4d43dfce05ca9c4835 Mon Sep 17 00:00:00 2001 From: Federico Pasqua Date: Sat, 14 Mar 2020 15:46:36 +0100 Subject: General upgrade for clippy fix and remove of deprecated methods for errors --- src/error.rs | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) (limited to 'src/error.rs') 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, + cause: Box, }, /// 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), + Foreign(Box), } 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(msg: T) -> Self { -- cgit v1.2.3