Compare commits

..

1 commit

Author SHA1 Message Date
Tristan Daniël Maat 65dd6da947
Complete day 4.2 2020-12-04 21:43:32 +00:00

View file

@ -17,14 +17,16 @@ fn parse_passports(input: &str) -> Result<Vec<HashMap<&str, &str>>, &str> {
.trim()
.split(|c| c == ' ' || c == '\n')
.map(|field| {
let split = field.find(':').ok_or("Invalid passport entry; no separator")?;
let split = field
.find(':')
.ok_or("Invalid passport entry; no separator")?;
let item = field.split_at(split);
let key = item.0;
let value = item
.1
.strip_prefix(":")
.ok_or("Invalid entry; value too short")?;
.expect("We've already checked the separator exists");
Ok((key, value))
})