by hocuspocus · 7y ago · 0 comments
Regarding parsing, a lot of times the input format is unnecessarily complex. In "real-life", wouldn't you start by sanitizing your input? For me, search/replace and column-edits have been enough to avoid regexps entirely.
input
.lines()
.map(|s| s.trim())
.filter(|l| l.len() > 0)
.map(CustomType::from)
.collect::<Vec<_>>();
or for grid-like puzzels input
.lines()
.map(|s| s.trim())
.filter(|l| l.len() > 0)
.map(|l| l
.chars()
.map(CustomType::from)
.collect::<Vec<_>>()
)
.collect::<Vec<_>>();
0: https://github.com/k0nserv/advent-of-rust-2018