~matthiasbeyer/imag

b2dffff6e891fff3257f65684599a36e13b451a3 — Matthias Beyer 2 years ago df5bfd1
Outsource helper: getting the link partial from Entry

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 files changed, 8 insertions(+), 3 deletions(-)

M lib/entry/libimagentrylink/src/linkable.rs
M lib/entry/libimagentrylink/src/linkable.rs => lib/entry/libimagentrylink/src/linkable.rs +8 -3
@@ 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)>
{
    debug!("Altering linkage of {:?} and {:?}", left, right);

    let get_partial = |entry: &mut Entry| -> Result<LinkPartial> {
        Ok(entry.get_header().read_partial::<LinkPartial>()?.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<F>(left: &mut Entry, right: &mut Entry, f: F) -> Result<()>
    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)]
mod test {
    use std::path::PathBuf;