From 52eb81a6f78833a2b3135f55b407e3123e789f06 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Mar 2016 14:41:34 +0100 Subject: [PATCH] Add initial codebase --- libimagentrylist/src/error.rs | 83 ++++++++++++++++++++++++++++++++++ libimagentrylist/src/lib.rs | 4 ++ libimagentrylist/src/lister.rs | 10 ++++ libimagentrylist/src/result.rs | 6 +++ 4 files changed, 103 insertions(+) create mode 100644 libimagentrylist/src/error.rs create mode 100644 libimagentrylist/src/lister.rs create mode 100644 libimagentrylist/src/result.rs diff --git a/libimagentrylist/src/error.rs b/libimagentrylist/src/error.rs new file mode 100644 index 00000000..82f6b387 --- /dev/null +++ b/libimagentrylist/src/error.rs @@ -0,0 +1,83 @@ +use std::error::Error; +use std::fmt::Error as FmtError; +use std::clone::Clone; +use std::fmt::{Display, Formatter}; + +/** + * Kind of error + */ +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum ListErrorKind { + FormatError, + EntryError, + IterationError +} + +fn counter_error_type_as_str(err: &ListErrorKind) -> &'static str{ + match err { + &ListErrorKind::FormatError => "FormatError", + &ListErrorKind::EntryError => "EntryError", + &ListErrorKind::IterationError => "IterationError", + } +} + +impl Display for ListErrorKind { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "{}", counter_error_type_as_str(self))); + Ok(()) + } + +} + +/** + * Store error type + */ +#[derive(Debug)] +pub struct ListError { + err_type: ListErrorKind, + cause: Option>, +} + +impl ListError { + + /** + * Build a new ListError from an ListErrorKind, optionally with cause + */ + pub fn new(errtype: ListErrorKind, cause: Option>) -> ListError { + ListError { + err_type: errtype, + cause: cause, + } + } + + /** + * Get the error type of this ListError + */ + pub fn err_type(&self) -> ListErrorKind { + self.err_type.clone() + } + +} + +impl Display for ListError { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + try!(write!(fmt, "[{}]", counter_error_type_as_str(&self.err_type.clone()))); + Ok(()) + } + +} + +impl Error for ListError { + + fn description(&self) -> &str { + counter_error_type_as_str(&self.err_type.clone()) + } + + fn cause(&self) -> Option<&Error> { + self.cause.as_ref().map(|e| &**e) + } + +} + diff --git a/libimagentrylist/src/lib.rs b/libimagentrylist/src/lib.rs index 880c1231..b47d1f2e 100644 --- a/libimagentrylist/src/lib.rs +++ b/libimagentrylist/src/lib.rs @@ -3,3 +3,7 @@ extern crate toml; extern crate libimagstore; +pub mod error; +pub mod lister; +pub mod result; + diff --git a/libimagentrylist/src/lister.rs b/libimagentrylist/src/lister.rs new file mode 100644 index 00000000..b54328e6 --- /dev/null +++ b/libimagentrylist/src/lister.rs @@ -0,0 +1,10 @@ +use libimagstore::store::FileLockEntry; + +use result::Result; + +pub trait Lister { + + fn list<'a, I: Iterator>>(&self, entries: I) -> Result<()>; + +} + diff --git a/libimagentrylist/src/result.rs b/libimagentrylist/src/result.rs new file mode 100644 index 00000000..729cce41 --- /dev/null +++ b/libimagentrylist/src/result.rs @@ -0,0 +1,6 @@ +use std::result::Result as RResult; + +use error::ListError; + +pub type Result = RResult; +