4 ms·
Nice article though some of the code is less elegant than it could be, normally you would match the option to unwrap it and then match it's value, instead of do
by nulldata 12y ago
Nice article though some of the code is less elegant than it could be, normally you would match the option to unwrap it and then match it's value, instead of doing a lot of 'Some( .. )' matches.
let first_character = match line.chars().next() {
Some( v ) => v,
None => return
}
match first_character {
'# => println!("Comment"),
...
}
- PudgePacket 12y agoI played around with a few different configurations for that particular part, even having something similar to yours that looked like match line.chars().next() { Some(x) => match x { '#' => ... 'v' => ... _ => ... }, None => ... } But I felt that the current approach was fine. At this point it becomes more a decision of style and taste vs any kind of practicality.