diff options
Diffstat (limited to 'libimaglink')
-rw-r--r-- | libimaglink/src/internal.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libimaglink/src/internal.rs b/libimaglink/src/internal.rs index b87e0783..da37d256 100644 --- a/libimaglink/src/internal.rs +++ b/libimaglink/src/internal.rs @@ -1,4 +1,5 @@ use libimagstore::store::EntryHeader; +use libimagstore::store::Result as StoreResult; use error::{LinkError, LinkErrorKind}; use link::{Link, Links}; @@ -21,3 +22,27 @@ pub fn add_link(header: &mut EntryHeader, link: Link) -> Result<()> { unimplemented!() } +fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Links> { + if links.is_err() { + let lerr = LinkError::new(LinkErrorKind::EntryHeaderReadError, + Some(Box::new(links.err().unwrap()))); + return Err(lerr); + } + let links = links.unwrap(); + + if links.iter().any(|l| match l { &Value::String(_) => true, _ => false }) { + return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None)); + } + + let links : Vec<Link> = links.into_iter() + .map(|link| { + match link { + Value::String(s) => Link::new(s), + _ => unreachable!(), + } + }) + .collect(); + + Ok(Links::new(links)) +} + |