Skip to content

Commit 7153736

Browse files
authored
matching-brackets: rm needless collect (#1023)
clippy::needless_collect Instead, check whether element exists in collection during iteration. Helps address #1012
1 parent f58afa9 commit 7153736

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

exercises/matching-brackets/example.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ impl From<Vec<(char, char)>> for MatchingBrackets {
5757

5858
impl MatchingBrackets {
5959
fn contains(&self, other: &char) -> bool {
60-
let known = self
61-
.collection
62-
.keys()
63-
.chain(self.collection.values())
64-
.collect::<Vec<_>>();
65-
known.contains(&other)
60+
self.collection
61+
.iter()
62+
.any(|(k, v)| k == other || v == other)
6663
}
6764

6865
fn closer_for(&self, k: &char) -> Option<&char> {

0 commit comments

Comments
 (0)