diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-02-07 04:40:43 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-11 15:15:02 +0100 |
commit | e4fae4cfcf90f5f483ca8070d5edff564011869d (patch) | |
tree | dded4e59563576b46503e33f093c0cdaea1fa0d1 /libimaglink | |
parent | 18de6b80d54adb4ae9658a8a11beaf804deed050 (diff) |
Implement: of external::set_link()
Diffstat (limited to 'libimaglink')
-rw-r--r-- | libimaglink/src/external.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/libimaglink/src/external.rs b/libimaglink/src/external.rs index 97b7dce4..1aa0c1ed 100644 --- a/libimaglink/src/external.rs +++ b/libimaglink/src/external.rs @@ -26,7 +26,25 @@ pub fn get_link(header: &EntryHeader) -> Result<Option<Link>> { /// Set an external link in the header /// /// Return the previous set link if there was any -pub fn set_link(header: &mut EntryHeader, l: Link) -> Option<Link> { - unimplemented!() +pub fn set_link(header: &mut EntryHeader, l: Link) -> Result<Option<Link>> { + let old_link = header.set("imag.content.uri", Value::String(l.into())); + + if old_link.is_err() { + let kind = LinkErrorKind::EntryHeaderWriteError; + let lerr = LinkError::new(kind, Some(Box::new(old_link.err().unwrap()))); + return Err(lerr); + } + let old_link = old_link.unwrap(); + + if old_link.is_none() { + return Ok(None); + } + + match old_link.unwrap() { + Value::String(s) => Ok(Some(Link::new(s))), + + // We don't do anything in this case and be glad we corrected the type error with this set() + _ => Ok(None), + } } |