diff --git a/src/error.rs b/src/error.rs index 416eb8c..75168e0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -438,7 +438,7 @@ impl From for Error { impl Display for Kind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Kind::Message(msg) => f.write_str(&msg), + Kind::Message(msg) => f.write_str(msg), Kind::InvalidType(v, exp) => { write!(f, "invalid type: found {}, expected {}", v, exp) } diff --git a/src/figment.rs b/src/figment.rs index 8b2534a..76d0277 100644 --- a/src/figment.rs +++ b/src/figment.rs @@ -159,8 +159,7 @@ impl Figment { (Err(e), Err(prev)) => Err(e.retagged(tag).chain(prev)), (Ok(mut new), Ok(old)) => { new.iter_mut() - .map(|(p, map)| std::iter::repeat(p).zip(map.values_mut())) - .flatten() + .flat_map(|(p, map)| std::iter::repeat(p).zip(map.values_mut())) .for_each(|(p, v)| v.map_tag(|t| *t = tag.for_profile(p))); Ok(old.coalesce(new, order)) diff --git a/src/jail.rs b/src/jail.rs index 22d4a2b..4dea3ba 100644 --- a/src/jail.rs +++ b/src/jail.rs @@ -320,9 +320,7 @@ impl Jail { pub fn clear_env(&mut self) { for (key, val) in std::env::vars_os() { std::env::remove_var(&key); - if !self.saved_env_vars.contains_key(&key) { - self.saved_env_vars.insert(key, Some(val)); - } + self.saved_env_vars.entry(key).or_insert(Some(val)); } } @@ -356,7 +354,7 @@ impl Jail { impl Drop for Jail { fn drop(&mut self) { - for (key, value) in self.saved_env_vars.iter() { + for (key, value) in &self.saved_env_vars { match value { Some(val) => std::env::set_var(key, val), None => std::env::remove_var(key) diff --git a/src/metadata.rs b/src/metadata.rs index ccc1da7..09a4cc3 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -292,7 +292,7 @@ impl fmt::Display for Source { Source::File(p) => { use {std::env::current_dir, crate::util::diff_paths}; - match current_dir().ok().and_then(|cwd| diff_paths(p, &cwd)) { + match current_dir().ok().and_then(|cwd| diff_paths(p, cwd)) { Some(r) if r.iter().count() < p.iter().count() => r.display().fmt(f), Some(_) | None => p.display().fmt(f) } diff --git a/src/providers/data.rs b/src/providers/data.rs index 5964579..2e0d740 100644 --- a/src/providers/data.rs +++ b/src/providers/data.rs @@ -290,10 +290,10 @@ impl Provider for Data { use Source::*; let map: Result, _> = match (&self.source, &self.profile) { (File(None), _) => return Ok(Map::new()), - (File(Some(path)), None) => F::from_path(&path), - (String(s), None) => F::from_str(&s), - (File(Some(path)), Some(prof)) => F::from_path(&path).map(|v| prof.collect(v)), - (String(s), Some(prof)) => F::from_str(&s).map(|v| prof.collect(v)), + (File(Some(path)), None) => F::from_path(path), + (String(s), None) => F::from_str(s), + (File(Some(path)), Some(prof)) => F::from_path(path).map(|v| prof.collect(v)), + (String(s), Some(prof)) => F::from_str(s).map(|v| prof.collect(v)), }; Ok(map.map_err(|e| e.to_string())?) diff --git a/src/providers/env.rs b/src/providers/env.rs index 7cc5d54..19c4275 100644 --- a/src/providers/env.rs +++ b/src/providers/env.rs @@ -232,7 +232,7 @@ impl Env { pub fn filter(self, filter: F) -> Self where F: Fn(&UncasedStr) -> bool { - self.chain(move |prev| prev.filter(|v| filter(&v))) + self.chain(move |prev| prev.filter(|v| filter(v))) } /// Applys an additional mapping to the keys of environment variables being @@ -432,7 +432,7 @@ impl Env { /// }); /// ``` pub fn ignore(self, keys: &[&str]) -> Self { - let keys: Vec = keys.iter().map(|s| s.to_string()).collect(); + let keys: Vec = keys.iter().map(|s| (*s).to_string()).collect(); self.filter(move |key| !keys.iter().any(|k| k.as_str() == key)) } @@ -461,7 +461,7 @@ impl Env { /// }); /// ``` pub fn only(self, keys: &[&str]) -> Self { - let keys: Vec = keys.iter().map(|s| s.to_string()).collect(); + let keys: Vec = keys.iter().map(|s| (*s).to_string()).collect(); self.filter(move |key| keys.iter().any(|k| k.as_str() == key)) } diff --git a/src/util.rs b/src/util.rs index 2a18068..13b0930 100644 --- a/src/util.rs +++ b/src/util.rs @@ -84,8 +84,8 @@ pub fn diff_paths(path: P, base: B) -> Option } (None, _) => comps.push(Component::ParentDir), (Some(a), Some(b)) if comps.is_empty() && a == b => (), - (Some(a), Some(b)) if b == Component::CurDir => comps.push(a), - (Some(_), Some(b)) if b == Component::ParentDir => return None, + (Some(a), Some(Component::CurDir)) => comps.push(a), + (Some(_), Some(Component::ParentDir)) => return None, (Some(a), Some(_)) => { comps.push(Component::ParentDir); for _ in itb { diff --git a/src/value/de.rs b/src/value/de.rs index e3a20ab..b4ceb6f 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -99,7 +99,7 @@ impl<'de: 'c, 'c, I: Interpreter> Deserializer<'de> for ConfiguredValueDe<'c, I> _ => visitor.visit_some(self) }; - result.map_err(|e| e.retagged(tag).resolved(&config)) + result.map_err(|e| e.retagged(tag).resolved(config)) } fn deserialize_struct>( @@ -145,7 +145,7 @@ impl<'de: 'c, 'c, I: Interpreter> Deserializer<'de> for ConfiguredValueDe<'c, I> _ => self.deserialize_any(v) }; - result.map_err(|e| e.retagged(tag).resolved(&config)) + result.map_err(|e| e.retagged(tag).resolved(config)) } fn deserialize_newtype_struct>( @@ -432,10 +432,10 @@ impl<'de> Deserialize<'de> for Value { // Total hack to "fingerprint" our deserializer by checking if // human_readable changes, which does for ours but shouldn't for others. let (a, b) = (de.is_human_readable(), de.is_human_readable()); - if a != b { - de.deserialize_struct(Value::NAME, Value::FIELDS, ValueVisitor) - } else { + if a == b { de.deserialize_any(ValueVisitor) + } else { + de.deserialize_struct(Value::NAME, Value::FIELDS, ValueVisitor) } } } diff --git a/src/value/escape.rs b/src/value/escape.rs index 28bff03..5a32f63 100644 --- a/src/value/escape.rs +++ b/src/value/escape.rs @@ -37,7 +37,7 @@ pub fn escape(string: &str) -> Result, Error> { Some((_, 'n')) => val.push('\n'), Some((_, 'r')) => val.push('\r'), Some((_, 't')) => val.push('\t'), - Some((i, c @ 'u')) | Some((i, c @ 'U')) => { + Some((i, c @ ('u' | 'U'))) => { let len = if c == 'u' { 4 } else { 8 }; val.push(hex(&mut chars, i, len)?); } @@ -64,7 +64,7 @@ fn hex(mut chars: I, i: usize, len: usize) -> Result let mut buf = String::with_capacity(len); for _ in 0..len { match chars.next() { - Some((_, ch)) if ch as u32 <= 0x7F && ch.is_digit(16) => buf.push(ch), + Some((_, ch)) if ch as u32 <= 0x7F && ch.is_ascii_hexdigit() => buf.push(ch), Some((i, ch)) => return Err(Error::InvalidHexEscape(i, ch)), None => return Err(Error::UnterminatedString(0)), } diff --git a/src/value/magic.rs b/src/value/magic.rs index 3e1da38..ab37974 100644 --- a/src/value/magic.rs +++ b/src/value/magic.rs @@ -203,7 +203,7 @@ impl Magic for RelativePathBuf { } // If we have this struct with no metadata_path, still use the value. - let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(&de.value); + let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(de.value); map.insert(Self::FIELDS[1].into(), value.clone()); visitor.visit_map(MapDe::new(&map, |v| ConfiguredValueDe::::from(config, v))) } @@ -592,7 +592,7 @@ impl Deserialize<'de>> Magic for Tagged { } // If we have this struct with default tag, use the value. - let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(&de.value); + let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(de.value); map.insert(Self::FIELDS[0].into(), de.value.tag().into()); map.insert(Self::FIELDS[1].into(), value.clone()); visitor.visit_map(MapDe::new(&map, |v| ConfiguredValueDe::::from(config, v))) diff --git a/src/value/ser.rs b/src/value/ser.rs index 1d530a7..83ae920 100644 --- a/src/value/ser.rs +++ b/src/value/ser.rs @@ -231,14 +231,15 @@ impl SeqSerializer { } } -impl<'a> ser::SerializeSeq for SeqSerializer { +impl ser::SerializeSeq for SeqSerializer { type Ok = Value; type Error = Error; fn serialize_element(&mut self, value: &T) -> Result<()> where T: Serialize { - Ok(self.sequence.push(value.serialize(ValueSerializer)?)) + self.sequence.push(value.serialize(ValueSerializer)?); + Ok(()) } fn end(self) -> Result { @@ -250,7 +251,7 @@ impl<'a> ser::SerializeSeq for SeqSerializer { } } -impl<'a> ser::SerializeTuple for SeqSerializer { +impl ser::SerializeTuple for SeqSerializer { type Ok = Value; type Error = Error; @@ -266,7 +267,7 @@ impl<'a> ser::SerializeTuple for SeqSerializer { } // Same thing but for tuple structs. -impl<'a> ser::SerializeTupleStruct for SeqSerializer { +impl ser::SerializeTupleStruct for SeqSerializer { type Ok = Value; type Error = Error; @@ -281,7 +282,7 @@ impl<'a> ser::SerializeTupleStruct for SeqSerializer { } } -impl<'a> ser::SerializeTupleVariant for SeqSerializer { +impl ser::SerializeTupleVariant for SeqSerializer { type Ok = Value; type Error = Error; @@ -306,7 +307,7 @@ impl MapSerializer { } } -impl<'a> ser::SerializeMap for MapSerializer { +impl ser::SerializeMap for MapSerializer { type Ok = Value; type Error = Error; @@ -329,7 +330,7 @@ impl<'a> ser::SerializeMap for MapSerializer { } fn end(self) -> Result { - let iter = self.keys.into_iter().zip(self.values.into_iter()); + let iter = self.keys.into_iter().zip(self.values); let value: Value = iter.collect::().into(); match self.tag { Some(tag) => Ok(crate::util::map![tag => value].into()), @@ -338,7 +339,7 @@ impl<'a> ser::SerializeMap for MapSerializer { } } -impl<'a> ser::SerializeStruct for MapSerializer { +impl ser::SerializeStruct for MapSerializer { type Ok = Value; type Error = Error; @@ -354,7 +355,7 @@ impl<'a> ser::SerializeStruct for MapSerializer { } } -impl<'a> ser::SerializeStructVariant for MapSerializer { +impl ser::SerializeStructVariant for MapSerializer { type Ok = Value; type Error = Error; diff --git a/src/value/tag.rs b/src/value/tag.rs index cb35323..c989e7b 100644 --- a/src/value/tag.rs +++ b/src/value/tag.rs @@ -109,21 +109,21 @@ impl PartialEq for Tag { impl Eq for Tag { } -impl PartialOrd for Tag { - fn partial_cmp(&self, other: &Self) -> Option { - self.metadata_id().partial_cmp(&other.metadata_id()) - } -} - impl Ord for Tag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.metadata_id().cmp(&other.metadata_id()) } } +impl PartialOrd for Tag { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl std::hash::Hash for Tag { fn hash(&self, state: &mut H) { - state.write_u64(self.metadata_id()) + state.write_u64(self.metadata_id()); } } diff --git a/src/value/value.rs b/src/value/value.rs index 25655cd..fe5f577 100644 --- a/src/value/value.rs +++ b/src/value/value.rs @@ -177,7 +177,7 @@ impl Value { /// assert!(value.find_ref("pineapple").is_none()); /// ``` pub fn find_ref<'a>(&'a self, path: &str) -> Option<&'a Value> { - fn find<'a, 'v>(mut keys: Split<'a, char>, value: &'v Value) -> Option<&'v Value> { + fn find<'v>(mut keys: Split, value: &'v Value) -> Option<&'v Value> { match keys.next() { Some(k) if !k.is_empty() => find(keys, value.as_dict()?.get(k)?), Some(_) | None => Some(value) @@ -462,7 +462,7 @@ impl<'a, T: Into + Clone> From<&'a [T]> for Value { } } -impl<'a, T: Into> From> for Value { +impl> From> for Value { fn from(vec: Vec) -> Value { let vector = vec.into_iter().map(|v| v.into()).collect(); Value::Array(Tag::Default, vector) @@ -577,7 +577,7 @@ impl Num { Some(match self { Num::U8(v) => v as u32, Num::U16(v) => v as u32, - Num::U32(v) => v as u32, + Num::U32(v) => v, _ => return None, }) } @@ -598,7 +598,7 @@ impl Num { Num::U16(v) => v as u128, Num::U32(v) => v as u128, Num::U64(v) => v as u128, - Num::U128(v) => v as u128, + Num::U128(v) => v, Num::USize(v) => v as u128, _ => return None, }) @@ -624,7 +624,7 @@ impl Num { Num::U16(v) => v as u128, Num::U32(v) => v as u128, Num::U64(v) => v as u128, - Num::U128(v) => v as u128, + Num::U128(v) => v, Num::USize(v) => v as u128, Num::I8(v) if v >= 0 => v as u128, Num::I16(v) if v >= 0 => v as u128, @@ -653,7 +653,7 @@ impl Num { Num::I16(v) => v as i128, Num::I32(v) => v as i128, Num::I64(v) => v as i128, - Num::I128(v) => v as i128, + Num::I128(v) => v, Num::ISize(v) => v as i128, _ => return None, }) @@ -673,7 +673,7 @@ impl Num { pub fn to_f64(&self) -> Option { Some(match *self { Num::F32(v) => v as f64, - Num::F64(v) => v as f64, + Num::F64(v) => v, _ => return None, }) } @@ -703,16 +703,16 @@ impl Num { Num::U16(v) => Actual::Unsigned(v as u128), Num::U32(v) => Actual::Unsigned(v as u128), Num::U64(v) => Actual::Unsigned(v as u128), - Num::U128(v) => Actual::Unsigned(v as u128), + Num::U128(v) => Actual::Unsigned(v), Num::USize(v) => Actual::Unsigned(v as u128), Num::I8(v) => Actual::Signed(v as i128), Num::I16(v) => Actual::Signed(v as i128), Num::I32(v) => Actual::Signed(v as i128), Num::I64(v) => Actual::Signed(v as i128), - Num::I128(v) => Actual::Signed(v as i128), + Num::I128(v) => Actual::Signed(v), Num::ISize(v) => Actual::Signed(v as i128), Num::F32(v) => Actual::Float(v as f64), - Num::F64(v) => Actual::Float(v as f64), + Num::F64(v) => Actual::Float(v), } } }