diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs index 3e8c1161..0f5a12ce 100644 --- a/libimagentrylink/src/internal.rs +++ b/libimagentrylink/src/internal.rs @@ -114,17 +114,22 @@ fn links_into_values(links: Vec) -> Vec> { } fn rewrite_links(header: &mut EntryHeader, links: Vec) -> 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(|_| ()) - } + 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.