Compare commits
1 commit
735089ad42
...
65dd6da947
Author | SHA1 | Date | |
---|---|---|---|
Tristan Daniël Maat | 65dd6da947 |
|
@ -17,14 +17,16 @@ fn parse_passports(input: &str) -> Result<Vec<HashMap<&str, &str>>, &str> {
|
||||||
.trim()
|
.trim()
|
||||||
.split(|c| c == ' ' || c == '\n')
|
.split(|c| c == ' ' || c == '\n')
|
||||||
.map(|field| {
|
.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 item = field.split_at(split);
|
||||||
|
|
||||||
let key = item.0;
|
let key = item.0;
|
||||||
let value = item
|
let value = item
|
||||||
.1
|
.1
|
||||||
.strip_prefix(":")
|
.strip_prefix(":")
|
||||||
.ok_or("Invalid entry; value too short")?;
|
.expect("We've already checked the separator exists");
|
||||||
|
|
||||||
Ok((key, value))
|
Ok((key, value))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue