Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Reuse the iterator
Browse files Browse the repository at this point in the history
Previously, a new iterator was created every time in the match arms out
of the original line.

With this change, the iterator is assigned to a variable, so that it can
be used both in the `match` and later in the match arms.
  • Loading branch information
pierreprinetti committed Jun 1, 2019
1 parent 1962bc2 commit e3e52e5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ fn main() {
let l = line.unwrap();
println!("{}", l);

match l.chars().next() {
let mut chars = l.chars();
match chars.next() {
Some('#') => {
last_date = l.chars().skip(3).take(10).collect();
last_date = chars.skip(2).take(10).collect();
},
Some('*') | Some('>') => {
items.insert(l.chars().skip(2).collect());
items.insert(chars.skip(1).collect());
},
Some('x') | Some('-') => {
let item: String = l.chars().skip(2).collect();
let item: String = chars.skip(1).collect();
items.remove(&item);
},
_ => (),
Expand Down

0 comments on commit e3e52e5

Please sign in to comment.