Skip to content

Commit dee3ac7

Browse files
committed
Simplify From<Vec>
exercism#178 (comment)
1 parent 5e8114d commit dee3ac7

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

exercises/bracket-push/example.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ pub struct MatchingBrackets {
4444
}
4545

4646
impl From<Vec<(char, char)>> for MatchingBrackets {
47-
fn from(i: Vec<(char, char)>) -> Self {
48-
let mut c: HashMap<char, char> = HashMap::new();
49-
50-
for (k, v) in i {
51-
c.insert(k, v);
52-
}
53-
54-
MatchingBrackets { collection: c }
47+
fn from(v: Vec<(char, char)>) -> Self {
48+
MatchingBrackets { collection: v.into_iter().collect::<HashMap<char, char>>() }
5549
}
5650
}
5751

0 commit comments

Comments
 (0)