Created
December 8, 2014 14:56
-
-
Save daxhuiberts/9da05585979667f7743a to your computer and use it in GitHub Desktop.
Bettering my Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// old one | |
fn process_stat(str: &str) -> Option<Vec<u32>> { | |
match STAT_REGEX.captures(str) { | |
Some(captures) => { | |
let iter = captures.at(1).split(' '); | |
let vec = iter.map(|x: &str| { | |
from_str(x).unwrap() | |
}).collect(); | |
Some(vec) | |
} | |
None => None | |
} | |
} | |
// new one (also safer because there is no unwrap anymore) | |
fn process_stat(str: &str) -> Option<Vec<u32>> { | |
STAT_REGEX.captures(str).and_then( |captures| { | |
let iter = captures.at(1).split(' '); | |
iter.map(from_str).collect() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment