Skip to content

Commit 436c964

Browse files
authored
Merge pull request #134 from eisterman/fix_clippy_warnings
Fix of all the clippy warnings and removing of deprecated Error::description method
2 parents 2c0b201 + e84a399 commit 436c964

File tree

20 files changed

+69
-96
lines changed

20 files changed

+69
-96
lines changed

examples/global/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ lazy_static! {
1111
static ref SETTINGS: RwLock<Config> = RwLock::new(Config::default());
1212
}
1313

14-
fn try_main() -> Result<(), Box<Error>> {
14+
fn try_main() -> Result<(), Box<dyn Error>> {
1515
// Set property
1616
SETTINGS.write()?.set("property", 42)?;
1717

examples/hierarchical-env/src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Settings {
4646
// Add in the current environment file
4747
// Default to 'development' env
4848
// Note that this file is _optional_
49-
let env = env::var("RUN_MODE").unwrap_or("development".into());
49+
let env = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());
5050
s.merge(File::with_name(&format!("config/{}", env)).required(false))?;
5151

5252
// Add in a local configuration file

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum ConfigKind {
1818
Mutable {
1919
defaults: HashMap<path::Expression, Value>,
2020
overrides: HashMap<path::Expression, Value>,
21-
sources: Vec<Box<Source + Send + Sync>>,
21+
sources: Vec<Box<dyn Source + Send + Sync>>,
2222
},
2323

2424
// A frozen configuration.
@@ -212,7 +212,7 @@ impl Config {
212212
}
213213

214214
impl Source for Config {
215-
fn clone_into_box(&self) -> Box<Source + Send + Sync> {
215+
fn clone_into_box(&self) -> Box<dyn Source + Send + Sync> {
216216
Box::new((*self).clone())
217217
}
218218

src/de.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'de> de::Deserializer<'de> for Value {
125125
where
126126
V: de::Visitor<'de>,
127127
{
128-
visitor.visit_enum(EnumAccess{ value: self, name: name, variants: variants })
128+
visitor.visit_enum(EnumAccess{ value: self, name, variants })
129129
}
130130

131131
forward_to_deserialize_any! {
@@ -241,12 +241,12 @@ struct EnumAccess {
241241
}
242242

243243
impl EnumAccess {
244-
fn variant_deserializer(&self, name: &String) -> Result<StrDeserializer> {
244+
fn variant_deserializer(&self, name: &str) -> Result<StrDeserializer> {
245245
self.variants
246246
.iter()
247-
.find(|&s| s == name)
247+
.find(|&&s| s == name)
248248
.map(|&s| StrDeserializer(s))
249-
.ok_or(self.no_constructor_error(name))
249+
.ok_or_else(|| self.no_constructor_error(name))
250250
}
251251

252252
fn table_deserializer(&self, table: &Table) -> Result<StrDeserializer> {
@@ -448,7 +448,7 @@ impl<'de> de::Deserializer<'de> for Config {
448448
where
449449
V: de::Visitor<'de>,
450450
{
451-
visitor.visit_enum(EnumAccess{ value: self.cache, name: name, variants: variants })
451+
visitor.visit_enum(EnumAccess{ value: self.cache, name, variants })
452452
}
453453

454454
forward_to_deserialize_any! {

src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Default for Environment {
6363
}
6464

6565
impl Source for Environment {
66-
fn clone_into_box(&self) -> Box<Source + Send + Sync> {
66+
fn clone_into_box(&self) -> Box<dyn Source + Send + Sync> {
6767
Box::new((*self).clone())
6868
}
6969

src/error.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum ConfigError {
5151

5252
/// The captured error from attempting to parse the file in its desired format.
5353
/// This is the actual error object from the library used for the parsing.
54-
cause: Box<Error + Send + Sync>,
54+
cause: Box<dyn Error + Send + Sync>,
5555
},
5656

5757
/// Value could not be converted into the requested type.
@@ -76,7 +76,7 @@ pub enum ConfigError {
7676
Message(String),
7777

7878
/// Unadorned error from a foreign origin.
79-
Foreign(Box<Error + Send + Sync>),
79+
Foreign(Box<dyn Error + Send + Sync>),
8080
}
8181

8282
impl ConfigError {
@@ -88,9 +88,9 @@ impl ConfigError {
8888
expected: &'static str,
8989
) -> Self {
9090
ConfigError::Type {
91-
origin: origin,
92-
unexpected: unexpected,
93-
expected: expected,
91+
origin,
92+
unexpected,
93+
expected,
9494
key: None,
9595
}
9696
}
@@ -105,9 +105,9 @@ impl ConfigError {
105105
expected,
106106
..
107107
} => ConfigError::Type {
108-
origin: origin,
109-
unexpected: unexpected,
110-
expected: expected,
108+
origin,
109+
unexpected,
110+
expected,
111111
key: Some(key.into()),
112112
},
113113

@@ -166,7 +166,9 @@ impl fmt::Debug for ConfigError {
166166
impl fmt::Display for ConfigError {
167167
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
168168
match *self {
169-
ConfigError::Frozen | ConfigError::PathParse(_) => write!(f, "{}", self.description()),
169+
ConfigError::Frozen => write!(f, "configuration is frozen"),
170+
171+
ConfigError::PathParse(ref kind) => write!(f, "{}", kind.description()),
170172

171173
ConfigError::Message(ref s) => write!(f, "{}", s),
172174

@@ -208,31 +210,7 @@ impl fmt::Display for ConfigError {
208210
}
209211
}
210212

211-
impl Error for ConfigError {
212-
fn description(&self) -> &str {
213-
match *self {
214-
ConfigError::Frozen => "configuration is frozen",
215-
ConfigError::NotFound(_) => "configuration property not found",
216-
ConfigError::Type { .. } => "invalid type",
217-
ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => {
218-
cause.description()
219-
}
220-
ConfigError::PathParse(ref kind) => kind.description(),
221-
222-
_ => "configuration error",
223-
}
224-
}
225-
226-
fn cause(&self) -> Option<&Error> {
227-
match *self {
228-
ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => {
229-
Some(cause.as_ref())
230-
}
231-
232-
_ => None,
233-
}
234-
}
235-
}
213+
impl Error for ConfigError { }
236214

237215
impl de::Error for ConfigError {
238216
fn custom<T: fmt::Display>(msg: T) -> Self {

src/file/format/hjson.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use value::{Value, ValueKind};
77
pub fn parse(
88
uri: Option<&String>,
99
text: &str,
10-
) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
10+
) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
1111
// Parse a JSON object value from the text
1212
// TODO: Have a proper error fire if the root of a file is ever not a Table
1313
let value = from_hjson_value(uri, &serde_hjson::from_str(text)?);

src/file/format/ini.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use value::{Value, ValueKind};
77
pub fn parse(
88
uri: Option<&String>,
99
text: &str,
10-
) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
10+
) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
1111
let mut map: HashMap<String, Value> = HashMap::new();
1212
let i = Ini::load_from_str(text)?;
1313
for (sec, prop) in i.iter() {

src/file/format/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use value::{Value, ValueKind};
77
pub fn parse(
88
uri: Option<&String>,
99
text: &str,
10-
) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
10+
) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
1111
// Parse a JSON object value from the text
1212
// TODO: Have a proper error fire if the root of a file is ever not a Table
1313
let value = from_json_value(uri, &serde_json::from_str(text)?);

src/file/format/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ lazy_static! {
7272
impl FileFormat {
7373
// TODO: pub(crate)
7474
#[doc(hidden)]
75-
pub fn extensions(&self) -> &'static Vec<&'static str> {
75+
pub fn extensions(self) -> &'static Vec<&'static str> {
7676
// It should not be possible for this to fail
7777
// A FileFormat would need to be declared without being added to the
7878
// ALL_EXTENSIONS map.
79-
ALL_EXTENSIONS.get(self).unwrap()
79+
ALL_EXTENSIONS.get(&self).unwrap()
8080
}
8181

8282
// TODO: pub(crate)
8383
#[doc(hidden)]
8484
#[allow(unused_variables)]
8585
pub fn parse(
86-
&self,
86+
self,
8787
uri: Option<&String>,
8888
text: &str,
89-
) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
90-
match *self {
89+
) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
90+
match self {
9191
#[cfg(feature = "toml")]
9292
FileFormat::Toml => toml::parse(uri, text),
9393

0 commit comments

Comments
 (0)