Add initial codebase
This commit is contained in:
parent
8b1c36a86e
commit
52eb81a6f7
4 changed files with 103 additions and 0 deletions
83
libimagentrylist/src/error.rs
Normal file
83
libimagentrylist/src/error.rs
Normal file
|
@ -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<Box<Error>>,
|
||||
}
|
||||
|
||||
impl ListError {
|
||||
|
||||
/**
|
||||
* Build a new ListError from an ListErrorKind, optionally with cause
|
||||
*/
|
||||
pub fn new(errtype: ListErrorKind, cause: Option<Box<Error>>) -> 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,3 +3,7 @@ extern crate toml;
|
|||
|
||||
extern crate libimagstore;
|
||||
|
||||
pub mod error;
|
||||
pub mod lister;
|
||||
pub mod result;
|
||||
|
||||
|
|
10
libimagentrylist/src/lister.rs
Normal file
10
libimagentrylist/src/lister.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use libimagstore::store::FileLockEntry;
|
||||
|
||||
use result::Result;
|
||||
|
||||
pub trait Lister {
|
||||
|
||||
fn list<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()>;
|
||||
|
||||
}
|
||||
|
6
libimagentrylist/src/result.rs
Normal file
6
libimagentrylist/src/result.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use std::result::Result as RResult;
|
||||
|
||||
use error::ListError;
|
||||
|
||||
pub type Result<T> = RResult<T, ListError>;
|
||||
|
Loading…
Reference in a new issue