Add initial interface spec
This commit is contained in:
parent
2430e68dc2
commit
ff3d5dd94b
6 changed files with 142 additions and 0 deletions
62
libimaglink/src/error.rs
Normal file
62
libimaglink/src/error.rs
Normal file
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
16
libimaglink/src/external.rs
Normal file
16
libimaglink/src/external.rs
Normal file
|
@ -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!()
|
||||
}
|
||||
|
18
libimaglink/src/internal.rs
Normal file
18
libimaglink/src/internal.rs
Normal file
|
@ -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!()
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
34
libimaglink/src/link.rs
Normal file
34
libimaglink/src/link.rs
Normal file
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
6
libimaglink/src/result.rs
Normal file
6
libimaglink/src/result.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use std::result::Result as RResult;
|
||||
|
||||
use error::LinkError;
|
||||
|
||||
pub type Result<T> = RResult<T, LinkError>;
|
||||
|
Loading…
Reference in a new issue