Outsource helper: getting the link partial from Entry

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-05 21:44:48 +02:00
parent df5bfd1ce3
commit b2dffff6e8

View file

@ -290,9 +290,8 @@ fn alter_linking<F>(left: &mut Entry, right: &mut Entry, f: F) -> Result<()>
where F: FnOnce(LinkPartial, LinkPartial) -> Result<(LinkPartial, LinkPartial)> where F: FnOnce(LinkPartial, LinkPartial) -> Result<(LinkPartial, LinkPartial)>
{ {
debug!("Altering linkage of {:?} and {:?}", left, right); debug!("Altering linkage of {:?} and {:?}", left, right);
let get_partial = |e| -> Result<_> {
let get_partial = |entry: &mut Entry| -> Result<LinkPartial> { Ok(get_link_partial(e)?.unwrap_or_else(LinkPartial::default))
Ok(entry.get_header().read_partial::<LinkPartial>()?.unwrap_or_else(LinkPartial::default))
}; };
let left_partial : LinkPartial = get_partial(left)?; let left_partial : LinkPartial = get_partial(left)?;
@ -313,6 +312,12 @@ fn alter_linking<F>(left: &mut Entry, right: &mut Entry, f: F) -> Result<()>
Ok(()) Ok(())
} }
fn get_link_partial(entry: &Entry) -> Result<Option<LinkPartial>> {
use failure::Error;
entry.get_header().read_partial::<LinkPartial>().map_err(Error::from)
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::path::PathBuf; use std::path::PathBuf;