diff --git a/src/config.rs b/src/config.rs index e54daa20..888d8ccf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,7 @@ enum ConfigKind { Mutable { defaults: HashMap, overrides: HashMap, - sources: Vec>, + sources: Vec>, }, // A frozen configuration. @@ -161,8 +161,7 @@ impl Config { match value { Some(value) => { // Deserialize the received value into the requested type - T::deserialize(value) - .map_err(|e| e.extend_with_key(key)) + T::deserialize(value).map_err(|e| e.extend_with_key(key)) } None => Err(ConfigError::NotFound(key.into())), @@ -212,7 +211,7 @@ impl Config { } impl Source for Config { - fn clone_into_box(&self) -> Box { + fn clone_into_box(&self) -> Box { Box::new((*self).clone()) } diff --git a/src/de.rs b/src/de.rs index 3c9e210c..57b81e0f 100644 --- a/src/de.rs +++ b/src/de.rs @@ -3,7 +3,7 @@ use error::*; use serde::de; use std::collections::{HashMap, VecDeque}; use std::iter::Enumerate; -use value::{Value, ValueKind, Table}; +use value::{Table, Value, ValueKind}; impl<'de> de::Deserializer<'de> for Value { type Error = ConfigError; @@ -125,7 +125,11 @@ impl<'de> de::Deserializer<'de> for Value { where V: de::Visitor<'de>, { - visitor.visit_enum(EnumAccess{ value: self, name: name, variants: variants }) + visitor.visit_enum(EnumAccess { + value: self, + name, + variants, + }) } forward_to_deserialize_any! { @@ -178,11 +182,10 @@ impl<'de> de::SeqAccess<'de> for SeqAccess { T: de::DeserializeSeed<'de>, { match self.elements.next() { - Some((idx, value)) => { - seed.deserialize(value) - .map(Some) - .map_err(|e| e.prepend_index(idx)) - } + Some((idx, value)) => seed + .deserialize(value) + .map(Some) + .map_err(|e| e.prepend_index(idx)), None => Ok(None), } } @@ -229,8 +232,7 @@ impl<'de> de::MapAccess<'de> for MapAccess { V: de::DeserializeSeed<'de>, { let (key, value) = self.elements.pop_front().unwrap(); - de::DeserializeSeed::deserialize(seed, value) - .map_err(|e| e.prepend_key(key)) + de::DeserializeSeed::deserialize(seed, value).map_err(|e| e.prepend_key(key)) } } @@ -241,12 +243,12 @@ struct EnumAccess { } impl EnumAccess { - fn variant_deserializer(&self, name: &String) -> Result { + fn variant_deserializer(&self, name: &str) -> Result { self.variants .iter() - .find(|&s| s == name) + .find(|&s| s == &name) .map(|&s| StrDeserializer(s)) - .ok_or(self.no_constructor_error(name)) + .ok_or_else(|| self.no_constructor_error(name)) } fn table_deserializer(&self, table: &Table) -> Result { @@ -315,21 +317,21 @@ impl<'de> de::VariantAccess<'de> for EnumAccess { V: de::Visitor<'de>, { match self.value.kind { - ValueKind::Table(t) => de::Deserializer::deserialize_seq(t.into_iter().next().unwrap().1, visitor), + ValueKind::Table(t) => { + de::Deserializer::deserialize_seq(t.into_iter().next().unwrap().1, visitor) + } _ => unreachable!(), } } - fn struct_variant( - self, - _fields: &'static [&'static str], - visitor: V, - ) -> Result + fn struct_variant(self, _fields: &'static [&'static str], visitor: V) -> Result where V: de::Visitor<'de>, { match self.value.kind { - ValueKind::Table(t) => de::Deserializer::deserialize_map(t.into_iter().next().unwrap().1, visitor), + ValueKind::Table(t) => { + de::Deserializer::deserialize_map(t.into_iter().next().unwrap().1, visitor) + } _ => unreachable!(), } } @@ -448,7 +450,11 @@ impl<'de> de::Deserializer<'de> for Config { where V: de::Visitor<'de>, { - visitor.visit_enum(EnumAccess{ value: self.cache, name: name, variants: variants }) + visitor.visit_enum(EnumAccess { + value: self.cache, + name, + variants, + }) } forward_to_deserialize_any! { diff --git a/src/env.rs b/src/env.rs index ce670695..06173838 100644 --- a/src/env.rs +++ b/src/env.rs @@ -63,7 +63,7 @@ impl Default for Environment { } impl Source for Environment { - fn clone_into_box(&self) -> Box { + fn clone_into_box(&self) -> Box { Box::new((*self).clone()) } diff --git a/src/error.rs b/src/error.rs index d7beeaff..32cb1bc5 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()), }, @@ -131,14 +131,12 @@ impl ConfigError { unexpected, expected, key, - } => { - ConfigError::Type { - origin, - unexpected, - expected, - key: Some(concat(key)), - } - } + } => ConfigError::Type { + origin, + unexpected, + expected, + key: Some(concat(key)), + }, ConfigError::NotFound(key) => ConfigError::NotFound(concat(Some(key))), _ => self, } @@ -166,7 +164,7 @@ 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 | ConfigError::PathParse(_) => write!(f, "{}", self.to_string()), ConfigError::Message(ref s) => write!(f, "{}", s), @@ -209,21 +207,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> { + fn cause(&self) -> Option<&dyn Error> { match *self { ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => { Some(cause.as_ref()) diff --git a/src/file/format/hjson.rs b/src/file/format/hjson.rs index cb0a0643..457cfbf5 100644 --- a/src/file/format/hjson.rs +++ b/src/file/format/hjson.rs @@ -7,7 +7,7 @@ use value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result, Box> { +) -> Result, Box> { // Parse a JSON object value from the text // TODO: Have a proper error fire if the root of a file is ever not a Table let value = from_hjson_value(uri, &serde_hjson::from_str(text)?); diff --git a/src/file/format/ini.rs b/src/file/format/ini.rs index 845de3a6..e5a109f8 100644 --- a/src/file/format/ini.rs +++ b/src/file/format/ini.rs @@ -7,7 +7,7 @@ use value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result, Box> { +) -> Result, Box> { let mut map: HashMap = HashMap::new(); let i = Ini::load_from_str(text)?; for (sec, prop) in i.iter() { @@ -15,22 +15,13 @@ pub fn parse( Some(ref sec) => { let mut sec_map: HashMap = HashMap::new(); for (k, v) in prop.iter() { - sec_map.insert( - k.clone(), - Value::new(uri, ValueKind::String(v.clone())), - ); + sec_map.insert(k.clone(), Value::new(uri, ValueKind::String(v.clone()))); } - map.insert( - sec.clone(), - Value::new(uri, ValueKind::Table(sec_map)), - ); + map.insert(sec.clone(), Value::new(uri, ValueKind::Table(sec_map))); } None => { for (k, v) in prop.iter() { - map.insert( - k.clone(), - Value::new(uri, ValueKind::String(v.clone())), - ); + map.insert(k.clone(), Value::new(uri, ValueKind::String(v.clone()))); } } } diff --git a/src/file/format/json.rs b/src/file/format/json.rs index 87240a3a..0ff2beb5 100644 --- a/src/file/format/json.rs +++ b/src/file/format/json.rs @@ -7,7 +7,7 @@ use value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result, Box> { +) -> Result, Box> { // Parse a JSON object value from the text // TODO: Have a proper error fire if the root of a file is ever not a Table let value = from_json_value(uri, &serde_json::from_str(text)?); @@ -22,13 +22,15 @@ fn from_json_value(uri: Option<&String>, value: &serde_json::Value) -> Value { match *value { serde_json::Value::String(ref value) => Value::new(uri, ValueKind::String(value.clone())), - serde_json::Value::Number(ref value) => if let Some(value) = value.as_i64() { - Value::new(uri, ValueKind::Integer(value)) - } else if let Some(value) = value.as_f64() { - Value::new(uri, ValueKind::Float(value)) - } else { - unreachable!(); - }, + serde_json::Value::Number(ref value) => { + if let Some(value) = value.as_i64() { + Value::new(uri, ValueKind::Integer(value)) + } else if let Some(value) = value.as_f64() { + Value::new(uri, ValueKind::Float(value)) + } else { + unreachable!(); + } + } serde_json::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)), diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs index 39b38135..f46ae134 100644 --- a/src/file/format/mod.rs +++ b/src/file/format/mod.rs @@ -72,22 +72,22 @@ lazy_static! { impl FileFormat { // TODO: pub(crate) #[doc(hidden)] - pub fn extensions(&self) -> &'static Vec<&'static str> { + pub fn extensions(self) -> &'static Vec<&'static str> { // It should not be possible for this to fail // A FileFormat would need to be declared without being added to the // ALL_EXTENSIONS map. - ALL_EXTENSIONS.get(self).unwrap() + ALL_EXTENSIONS.get(&self).unwrap() } // TODO: pub(crate) #[doc(hidden)] #[allow(unused_variables)] pub fn parse( - &self, + self, uri: Option<&String>, text: &str, - ) -> Result, Box> { - match *self { + ) -> Result, Box> { + match self { #[cfg(feature = "toml")] FileFormat::Toml => toml::parse(uri, text), diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs index 26dcb2ae..a40104eb 100644 --- a/src/file/format/toml.rs +++ b/src/file/format/toml.rs @@ -7,7 +7,7 @@ use value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result, Box> { +) -> Result, Box> { // Parse a TOML value from the provided text // TODO: Have a proper error fire if the root of a file is ever not a Table let value = from_toml_value(uri, &toml::from_str(text)?); diff --git a/src/file/format/yaml.rs b/src/file/format/yaml.rs index c2b26cb2..c458c3ce 100644 --- a/src/file/format/yaml.rs +++ b/src/file/format/yaml.rs @@ -9,7 +9,7 @@ use yaml_rust as yaml; pub fn parse( uri: Option<&String>, text: &str, -) -> Result, Box> { +) -> Result, Box> { // Parse a YAML object from file let mut docs = yaml::YamlLoader::load_from_str(text)?; let root = match docs.len() { diff --git a/src/file/mod.rs b/src/file/mod.rs index 342d09bf..73dfad4a 100644 --- a/src/file/mod.rs +++ b/src/file/mod.rs @@ -10,8 +10,8 @@ use value::Value; pub use self::format::FileFormat; use self::source::FileSource; -pub use self::source::string::FileSourceString; pub use self::source::file::FileSourceFile; +pub use self::source::string::FileSourceString; #[derive(Clone, Debug)] pub struct File @@ -94,7 +94,7 @@ where T: 'static, T: Sync + Send, { - fn clone_into_box(&self) -> Box { + fn clone_into_box(&self) -> Box { Box::new((*self).clone()) } @@ -119,9 +119,6 @@ where // Parse the string using the given format format .parse(uri.as_ref(), &contents) - .map_err(|cause| ConfigError::FileParse { - uri: uri, - cause: cause, - }) + .map_err(|cause| ConfigError::FileParse { uri, cause }) } } diff --git a/src/file/source/file.rs b/src/file/source/file.rs index a413a1fd..804d1085 100644 --- a/src/file/source/file.rs +++ b/src/file/source/file.rs @@ -21,13 +21,13 @@ pub struct FileSourceFile { impl FileSourceFile { pub fn new(name: PathBuf) -> FileSourceFile { - FileSourceFile { name: name } + FileSourceFile { name } } fn find_file( &self, format_hint: Option, - ) -> Result<(PathBuf, FileFormat), Box> { + ) -> Result<(PathBuf, FileFormat), Box> { // First check for an _exact_ match let mut filename = env::current_dir()?.as_path().join(self.name.clone()); if filename.is_file() { @@ -58,23 +58,27 @@ impl FileSourceFile { } match format_hint { - Some(format) => for ext in format.extensions() { - filename.set_extension(ext); - - if filename.is_file() { - return Ok((filename, format)); - } - }, - - None => for (format, extensions) in ALL_EXTENSIONS.iter() { + Some(format) => { for ext in format.extensions() { filename.set_extension(ext); if filename.is_file() { - return Ok((filename, *format)); + return Ok((filename, format)); } } - }, + } + + None => { + for (format, extensions) in ALL_EXTENSIONS.iter() { + for ext in format.extensions() { + filename.set_extension(ext); + + if filename.is_file() { + return Ok((filename, *format)); + } + } + } + } } Err(Box::new(io::Error::new( @@ -91,7 +95,7 @@ impl FileSource for FileSourceFile { fn resolve( &self, format_hint: Option, - ) -> Result<(Option, String, FileFormat), Box> { + ) -> Result<(Option, String, FileFormat), Box> { // Find file let (filename, format) = self.find_file(format_hint)?; @@ -103,7 +107,7 @@ impl FileSource for FileSourceFile { }; // Read contents from file - let mut file = fs::File::open(filename.clone())?; + let mut file = fs::File::open(filename)?; let mut text = String::new(); file.read_to_string(&mut text)?; diff --git a/src/file/source/mod.rs b/src/file/source/mod.rs index 5da69f13..ab276d07 100644 --- a/src/file/source/mod.rs +++ b/src/file/source/mod.rs @@ -12,5 +12,5 @@ pub trait FileSource: Debug + Clone { fn resolve( &self, format_hint: Option, - ) -> Result<(Option, String, FileFormat), Box>; + ) -> Result<(Option, String, FileFormat), Box>; } diff --git a/src/file/source/string.rs b/src/file/source/string.rs index a2f66cb0..3896cce6 100644 --- a/src/file/source/string.rs +++ b/src/file/source/string.rs @@ -19,7 +19,7 @@ impl FileSource for FileSourceString { fn resolve( &self, format_hint: Option, - ) -> Result<(Option, String, FileFormat), Box> { + ) -> Result<(Option, String, FileFormat), Box> { Ok(( None, self.0.clone(), diff --git a/src/path/mod.rs b/src/path/mod.rs index f63deee0..eb3964e7 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -151,35 +151,30 @@ impl Expression { _ => None, }, - Expression::Subscript(ref expr, index) => { - let mut do_again = false; - match expr.get_mut_forcibly(root) { - Some(value) => { - match value.kind { - ValueKind::Array(_) => (), - _ => *value = Vec::::new().into(), - } - - match value.kind { - ValueKind::Array(ref mut array) => { - let index = sindex_to_uindex(index, array.len()); + Expression::Subscript(ref expr, index) => match expr.get_mut_forcibly(root) { + Some(value) => { + match value.kind { + ValueKind::Array(_) => (), + _ => *value = Vec::::new().into(), + } - if index >= array.len() { - array.resize( - (index + 1) as usize, - Value::new(None, ValueKind::Nil), - ); - } + match value.kind { + ValueKind::Array(ref mut array) => { + let index = sindex_to_uindex(index, array.len()); - Some(&mut array[index]) + if index >= array.len() { + array + .resize((index + 1) as usize, Value::new(None, ValueKind::Nil)); } - _ => None, + Some(&mut array[index]) } + + _ => None, } - _ => None, } - } + _ => None, + }, } } @@ -244,20 +239,14 @@ impl Expression { _ => *parent = Vec::::new().into(), } - match parent.kind { - ValueKind::Array(ref mut array) => { - let uindex = sindex_to_uindex(index, array.len()); - if uindex >= array.len() { - array.resize( - (uindex + 1) as usize, - Value::new(None, ValueKind::Nil), - ); - } + if let ValueKind::Array(ref mut array) = parent.kind { + let uindex = sindex_to_uindex(index, array.len()); - array[uindex] = value.clone(); + if uindex >= array.len() { + array.resize((uindex + 1) as usize, Value::new(None, ValueKind::Nil)); } - _ => (), + array[uindex] = value; } } } diff --git a/src/path/parser.rs b/src/path/parser.rs index d783f3e9..7a40cb5a 100644 --- a/src/path/parser.rs +++ b/src/path/parser.rs @@ -1,49 +1,49 @@ use super::Expression; use nom::{ - IResult, Err, - error::ErrorKind, - bytes::complete::{is_a, tag}, - character::complete::{char, digit1, space0}, - sequence::{delimited, pair, preceded}, - branch::alt, - combinator::{map, map_res, opt, recognize}, + branch::alt, + bytes::complete::{is_a, tag}, + character::complete::{char, digit1, space0}, + combinator::{map, map_res, opt, recognize}, + error::ErrorKind, + sequence::{delimited, pair, preceded}, + Err, IResult, }; use std::str::{from_utf8, FromStr}; fn raw_ident(i: &str) -> IResult<&str, String> { - map(is_a( - "abcdefghijklmnopqrstuvwxyz \ + map( + is_a( + "abcdefghijklmnopqrstuvwxyz \ ABCDEFGHIJKLMNOPQRSTUVWXYZ \ 0123456789 \ - _-" - ), |s:&str| s.to_string())(i) + _-", + ), + |s: &str| s.to_string(), + )(i) } fn integer(i: &str) -> IResult<&str, isize> { - map_res( - delimited( - space0, - recognize(pair(opt(tag("-")), digit1)), - space0 - ), - FromStr::from_str - )(i) + map_res( + delimited(space0, recognize(pair(opt(tag("-")), digit1)), space0), + FromStr::from_str, + )(i) } fn ident(i: &str) -> IResult<&str, Expression> { - map(raw_ident, Expression::Identifier)(i) + map(raw_ident, Expression::Identifier)(i) } fn postfix<'a>(expr: Expression) -> impl Fn(&'a str) -> IResult<&'a str, Expression> { - let e2 = expr.clone(); - let child = map(preceded(tag("."), raw_ident), move |id| Expression::Child(Box::new(expr.clone()), id)); + let e2 = expr.clone(); + let child = map(preceded(tag("."), raw_ident), move |id| { + Expression::Child(Box::new(expr.clone()), id) + }); - let subscript = map(delimited(char('['), integer, char(']')), move |num| Expression::Subscript(Box::new(e2.clone()), num)); + let subscript = map(delimited(char('['), integer, char(']')), move |num| { + Expression::Subscript(Box::new(e2.clone()), num) + }); - alt(( - child, - subscript - )) + alt((child, subscript)) } pub fn from_str(input: &str) -> Result { @@ -72,10 +72,10 @@ pub fn from_str(input: &str) -> Result { } pub fn to_error_kind(e: Err<(&str, ErrorKind)>) -> ErrorKind { - match e { - Err::Incomplete(_) => ErrorKind::Complete, - Err::Failure((_, e)) | Err::Error((_, e)) => e, - } + match e { + Err::Incomplete(_) => ErrorKind::Complete, + Err::Failure((_, e)) | Err::Error((_, e)) => e, + } } #[cfg(test)] diff --git a/src/ser.rs b/src/ser.rs index b5b19edd..39c02b9b 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -48,10 +48,9 @@ impl ConfigSerializer { self.keys .get_mut(len - 1) .map(|pair| pair.1 = pair.1.map(|i| i + 1).or(Some(0))) - .ok_or(ConfigError::Message(format!( - "last key is not found in {} keys", - len - ))) + .ok_or_else(|| { + ConfigError::Message(format!("last key is not found in {} keys", len)) + }) } else { Err(ConfigError::Message("keys is empty".to_string())) } diff --git a/src/source.rs b/src/source.rs index e4c4972c..4d1ba534 100644 --- a/src/source.rs +++ b/src/source.rs @@ -7,7 +7,7 @@ use value::{Value, ValueKind}; /// Describes a generic _source_ of configuration properties. pub trait Source: Debug { - fn clone_into_box(&self) -> Box; + fn clone_into_box(&self) -> Box; /// Collect all configuration properties available from this source and return /// a HashMap. @@ -35,14 +35,14 @@ pub trait Source: Debug { } } -impl Clone for Box { - fn clone(&self) -> Box { +impl Clone for Box { + fn clone(&self) -> Box { self.clone_into_box() } } -impl Source for Vec> { - fn clone_into_box(&self) -> Box { +impl Source for Vec> { + fn clone_into_box(&self) -> Box { Box::new((*self).clone()) } @@ -67,7 +67,7 @@ where T: Clone, T: 'static, { - fn clone_into_box(&self) -> Box { + fn clone_into_box(&self) -> Box { Box::new((*self).clone()) } diff --git a/src/value.rs b/src/value.rs index 2db195d7..177acf73 100644 --- a/src/value.rs +++ b/src/value.rs @@ -39,7 +39,7 @@ where impl From for ValueKind { fn from(value: String) -> Self { - ValueKind::String(value.into()) + ValueKind::String(value) } } @@ -179,17 +179,17 @@ impl Value { // Unexpected type ValueKind::Nil => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Unit, "a boolean", )), ValueKind::Table(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Map, "a boolean", )), ValueKind::Array(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Seq, "a boolean", )), @@ -224,17 +224,17 @@ impl Value { // Unexpected type ValueKind::Nil => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Unit, "an integer", )), ValueKind::Table(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Map, "an integer", )), ValueKind::Array(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Seq, "an integer", )), @@ -269,17 +269,17 @@ impl Value { // Unexpected type ValueKind::Nil => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Unit, "a floating point", )), ValueKind::Table(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Map, "a floating point", )), ValueKind::Array(_) => Err(ConfigError::invalid_type( - self.origin.clone(), + self.origin, Unexpected::Seq, "a floating point", )), @@ -500,7 +500,7 @@ impl<'de> Deserialize<'de> for Value { { let mut vec = Array::new(); - while let Some(elem) = try!(visitor.next_element()) { + while let Some(elem) = visitor.next_element()? { vec.push(elem); } @@ -513,7 +513,7 @@ impl<'de> Deserialize<'de> for Value { { let mut values = Table::new(); - while let Some((key, value)) = try!(visitor.next_entry()) { + while let Some((key, value)) = visitor.next_entry()? { values.insert(key, value); } diff --git a/tests/errors.rs b/tests/errors.rs index 5f4a1a52..d332ad39 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -80,11 +80,14 @@ fn test_error_enum_de() { "value of enum Diode should be represented by either string or table with exactly one key" ); - - let confused_v: Value = - [("Brightness".to_string(), 100.into()), - ("Blinking".to_string(), vec![300, 700].into())] - .iter().cloned().collect::>().into(); + let confused_v: Value = [ + ("Brightness".to_string(), 100.into()), + ("Blinking".to_string(), vec![300, 700].into()), + ] + .iter() + .cloned() + .collect::>() + .into(); let confused_d = confused_v.try_into::(); assert_eq!( confused_d.unwrap_err().to_string(), @@ -111,7 +114,10 @@ inner: let mut cfg = Config::new(); cfg.merge(File::from_str(CFG, FileFormat::Yaml)).unwrap(); let e = cfg.try_into::().unwrap_err(); - if let ConfigError::Type { key: Some(path), .. } = e { + if let ConfigError::Type { + key: Some(path), .. + } = e + { assert_eq!(path, "inner.test"); } else { panic!("Wrong error {:?}", e); diff --git a/tests/get.rs b/tests/get.rs index 64196e55..10ec0662 100644 --- a/tests/get.rs +++ b/tests/get.rs @@ -224,7 +224,13 @@ fn test_enum() { assert_eq!(s.diodes["green"], Diode::Off); assert_eq!(s.diodes["red"], Diode::Brightness(100)); assert_eq!(s.diodes["blue"], Diode::Blinking(300, 700)); - assert_eq!(s.diodes["white"], Diode::Pattern{name: "christmas".into(), inifinite: true,}); + assert_eq!( + s.diodes["white"], + Diode::Pattern { + name: "christmas".into(), + inifinite: true, + } + ); } #[test]