[clippy] api-test: generalize HashSet impls and closure cleanups

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-22 09:02:36 +02:00
parent 4a33af4387
commit adf6727072
3 changed files with 5 additions and 7 deletions

View File

@ -62,9 +62,7 @@ impl<'de> serde::de::Visitor<'de> for StringListVisitor {
}
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let mut out = seq
.size_hint()
.map_or_else(Vec::new, |size| Vec::with_capacity(size));
let mut out = seq.size_hint().map_or_else(Vec::new, Vec::with_capacity);
loop {
match seq.next_element::<String>()? {
Some(el) => out.push(el),

View File

@ -13,7 +13,7 @@ pub trait ForEachStr {
F: FnMut(&str) -> Result<(), Error>;
}
impl ForEachStr for HashSet<String> {
impl<S: std::hash::BuildHasher> ForEachStr for HashSet<String, S> {
fn for_each_str<F>(&self, mut func: F) -> Result<(), Error>
where
F: FnMut(&str) -> Result<(), Error>,
@ -69,7 +69,7 @@ impl<'de> serde::de::Visitor<'de> for StringSetVisitor {
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let mut out = seq
.size_hint()
.map_or_else(HashSet::new, |size| HashSet::with_capacity(size));
.map_or_else(HashSet::new, HashSet::with_capacity);
loop {
match seq.next_element::<String>()? {
Some(el) => out.insert(el),

View File

@ -39,13 +39,13 @@ impl StringContainer for Option<Vec<String>> {
}
}
impl StringContainer for HashSet<String> {
impl<S: std::hash::BuildHasher> StringContainer for HashSet<String, S> {
fn all<F: Fn(&str) -> bool>(&self, pred: F) -> bool {
self.iter().all(|s| pred(s))
}
}
impl StringContainer for Option<HashSet<String>> {
impl<S: std::hash::BuildHasher> StringContainer for Option<HashSet<String, S>> {
fn all<F: Fn(&str) -> bool>(&self, pred: F) -> bool {
self.as_ref()
.map(|c| StringContainer::all(c, pred))