diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-02-03 15:47:14 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-11 15:15:02 +0100 |
commit | ff3d5dd94bd715125314024d48cfa085eb574fca (patch) | |
tree | 31e9c884b8c681af2882057b97814278207acbbd /libimaglink | |
parent | 2430e68dc261190e1d9080bd2078d06ab7ceb095 (diff) |
Add initial interface spec
Diffstat (limited to 'libimaglink')
-rw-r--r-- | libimaglink/src/error.rs | 62 | ||||
-rw-r--r-- | libimaglink/src/external.rs | 16 | ||||
-rw-r--r-- | libimaglink/src/internal.rs | 18 | ||||
-rw-r--r-- | libimaglink/src/lib.rs | 6 | ||||
-rw-r--r-- | libimaglink/src/link.rs | 34 | ||||
-rw-r--r-- | libimaglink/src/result.rs | 6 |
6 files changed, 142 insertions, 0 deletions
diff --git a/libimaglink/src/error.rs b/libimaglink/src/error.rs new file mode 100644 index 00000000..12be1366 --- /dev/null +++ b/libimaglink/src/error.rs @@ -0,0 +1,62 @@ +use std::error::Error; +use std::fmt::Error as FmtError; +use std::clone::Clone; +use std::fmt::{Debug, Display, Formatter}; +use std::fmt; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum LinkErrorKind { +} + +fn link_error_type_as_str(e: &LinkErrorKind) -> &'static str { + match e { + _ => unimplemented!(), + } +} + +impl Display for LinkErrorKind { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "{}", link_error_type_as_str(self))); + Ok(()) + } + +} + +#[derive(Debug)] +pub struct LinkError { + kind: LinkErrorKind, + cause: Option<Box<Error>>, +} + +impl LinkError { + + pub fn new(errtype: LinkErrorKind, cause: Option<Box<Error>>) -> LinkError { + LinkError { + kind: errtype, + cause: cause, + } + } + +} + +impl Display for LinkError { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "[{}]", link_error_type_as_str(&self.kind))); + Ok(()) + } + +} + +impl Error for LinkError { + + fn description(&self) -> &str { + link_error_type_as_str(&self.kind) + } + + fn cause(&self) -> Option<&Error> { + self.cause.as_ref().map(|e| &**e) + } + +} diff --git a/libimaglink/src/external.rs b/libimaglink/src/external.rs new file mode 100644 index 00000000..d30dec0b --- /dev/null +++ b/libimaglink/src/external.rs @@ -0,0 +1,16 @@ +use libimagstore::store::EntryHeader; + +use link::{Link, Links}; +use result::Result; + +pub fn get_link(header: &EntryHeader) -> Result<Link> { + unimplemented!() +} + +/// 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!() +} + diff --git a/libimaglink/src/internal.rs b/libimaglink/src/internal.rs new file mode 100644 index 00000000..1a964fc9 --- /dev/null +++ b/libimaglink/src/internal.rs @@ -0,0 +1,18 @@ +use libimagstore::store::EntryHeader; + +use error::{LinkError, LinkErrorKind}; +use link::{Link, Links}; +use result::Result; + +pub fn get_links(header: &EntryHeader) -> Result<Links> { + unimplemented!() +} + +pub fn set_links(header: &mut EntryHeader, links: Links) -> Result<Links> { + unimplemented!() +} + +pub fn add_link(header: &mut EntryHeader, link: Link) -> Result<()> { + unimplemented!() +} + diff --git a/libimaglink/src/lib.rs b/libimaglink/src/lib.rs index 880c1231..fdfa3d08 100644 --- a/libimaglink/src/lib.rs +++ b/libimaglink/src/lib.rs @@ -3,3 +3,9 @@ extern crate toml; extern crate libimagstore; +pub mod error; +pub mod external; +pub mod internal; +pub mod link; +pub mod result; + diff --git a/libimaglink/src/link.rs b/libimaglink/src/link.rs new file mode 100644 index 00000000..dcf60936 --- /dev/null +++ b/libimaglink/src/link.rs @@ -0,0 +1,34 @@ +use std::convert::Into; + +use libimagstore::store::Entry; + +pub struct Link { + link: String +} + +impl Link { +} + +pub struct Links { + links: Vec<Link>, +} + +impl Links { +} + +impl Into<String> for Link { + + fn into(self) -> String { + self.link + } + +} + +impl Into<Vec<Link>> for Links { + + fn into(self) -> Vec<Link> { + self.links + } + +} + diff --git a/libimaglink/src/result.rs b/libimaglink/src/result.rs new file mode 100644 index 00000000..587c0cac --- /dev/null +++ b/libimaglink/src/result.rs @@ -0,0 +1,6 @@ +use std::result::Result as RResult; + +use error::LinkError; + +pub type Result<T> = RResult<T, LinkError>; + |