From b2dffff6e891fff3257f65684599a36e13b451a3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 5 Oct 2019 21:44:48 +0200 Subject: [PATCH] Outsource helper: getting the link partial from Entry Signed-off-by: Matthias Beyer --- lib/entry/libimagentrylink/src/linkable.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/entry/libimagentrylink/src/linkable.rs b/lib/entry/libimagentrylink/src/linkable.rs index 038c8036..32157c3d 100644 --- a/lib/entry/libimagentrylink/src/linkable.rs +++ b/lib/entry/libimagentrylink/src/linkable.rs @@ -290,9 +290,8 @@ fn alter_linking(left: &mut Entry, right: &mut Entry, f: F) -> Result<()> where F: FnOnce(LinkPartial, LinkPartial) -> Result<(LinkPartial, LinkPartial)> { debug!("Altering linkage of {:?} and {:?}", left, right); - - let get_partial = |entry: &mut Entry| -> Result { - Ok(entry.get_header().read_partial::()?.unwrap_or_else(LinkPartial::default)) + let get_partial = |e| -> Result<_> { + Ok(get_link_partial(e)?.unwrap_or_else(LinkPartial::default)) }; let left_partial : LinkPartial = get_partial(left)?; @@ -313,6 +312,12 @@ fn alter_linking(left: &mut Entry, right: &mut Entry, f: F) -> Result<()> Ok(()) } +fn get_link_partial(entry: &Entry) -> Result> { + use failure::Error; + entry.get_header().read_partial::().map_err(Error::from) +} + + #[cfg(test)] mod test { use std::path::PathBuf;