Skip to content

Commit 82f0447

Browse files
authored
anagram, pythagorean-triplet: use collect() instead of from_iter() (#1027)
https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect Apparently it should be rare to call `from_iter()` directly. This lint is a fairly recent addition (merged 17 days ago): rust-lang/rust-clippy@a2bf404 Observing that the necessary code change still works on 1.47.0 (note that 1.48.0 was released very recently), it seems safe to make the change now.
1 parent ea5ea52 commit 82f0447

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

exercises/anagram/tests/anagram.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::collections::HashSet;
2-
use std::iter::FromIterator;
32

43
fn process_anagram_case(word: &str, inputs: &[&str], expected: &[&str]) {
54
let result = anagram::anagrams_for(word, inputs);
65

7-
let expected: HashSet<&str> = HashSet::from_iter(expected.iter().cloned());
6+
let expected: HashSet<&str> = expected.iter().cloned().collect();
87

98
assert_eq!(result, expected);
109
}

exercises/pythagorean-triplet/tests/pythagorean-triplet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use pythagorean_triplet::find;
2-
use std::{collections::HashSet, iter::FromIterator};
2+
use std::collections::HashSet;
33

44
fn process_tripletswithsum_case(sum: u32, expected: &[[u32; 3]]) {
55
let triplets = find(sum);
66

77
if !expected.is_empty() {
8-
let expected = HashSet::from_iter(expected.iter().cloned());
8+
let expected: HashSet<_> = expected.iter().cloned().collect();
99

1010
assert_eq!(expected, triplets);
1111
} else {

0 commit comments

Comments
 (0)