Replace map(unwrap()) with fold()
This commit is contained in:
parent
80491ff0b7
commit
41bf063a71
1 changed files with 15 additions and 10 deletions
|
@ -114,17 +114,22 @@ fn links_into_values(links: Vec<StoreId>) -> Vec<Option<Value>> {
|
|||
}
|
||||
|
||||
fn rewrite_links(header: &mut EntryHeader, links: Vec<StoreId>) -> Result<()> {
|
||||
let links = links_into_values(links);
|
||||
let links = try!(links_into_values(links)
|
||||
.into_iter()
|
||||
.fold(Ok(vec![]), |acc, elem| {
|
||||
acc.and_then(move |mut v| {
|
||||
match elem {
|
||||
None => Err(LEK::InternalConversionError.into()),
|
||||
Some(e) => {
|
||||
v.push(e);
|
||||
Ok(v)
|
||||
},
|
||||
}
|
||||
})
|
||||
}));
|
||||
|
||||
if links.iter().any(|o| o.is_none()) {
|
||||
// if any type convert failed we fail as well
|
||||
Err(LEK::InternalConversionError.into())
|
||||
} else {
|
||||
// I know it is ugly
|
||||
let links = links.into_iter().map(|opt| opt.unwrap()).collect();
|
||||
let process = header.set("imag.links", Value::Array(links));
|
||||
process_rw_result(process).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// When Linking A -> B, the specification wants us to link back B -> A.
|
||||
|
|
Loading…
Reference in a new issue