#[cfg(test)]
#[macro_use]
mod test_utils;
use query::ast::AST;
use std::fmt;
use std::io::Error as IOError;
use std::io::ErrorKind;
use task::{Note, Task};
#[derive(Debug)]
pub enum Error {
NotFound,
IO(IOError),
BadRequest(String),
}
impl From<IOError> for Error {
fn from(e: IOError) -> Error {
Error::IO(e)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::IO(s) => write!(f, "IO: {}", s),
Error::BadRequest(s) => write!(f, "BadRequest: {}", s),
Error::NotFound => write!(f, "No task matching that query found."),
}
}
}
impl Error {
pub fn into_io_err(self) -> IOError {
match self {
Error::IO(e) => e,
Error::NotFound => {
IOError::new(ErrorKind::NotFound, "No task matching that query found.")
}
Error::BadRequest(s) => IOError::new(ErrorKind::Other, s),
}
}
}
pub trait List {
fn add(&mut self, task: Task) -> Result<(), Error>;
fn add_multiple(&mut self, task: Vec<Task>) -> Result<(), Error>;
fn find_by_id(&mut self, id: String) -> Result<Task, Error>;
fn current(&mut self) -> Result<Task, Error>;
fn contexts(&mut self) -> Result<Vec<String>, Error>;
fn complete(&mut self, id: String) -> Result<(), Error>;
fn update(&mut self, task: Task) -> Result<(), Error>;
fn add_note(&mut self, id: String, note: Note) -> Result<(), Error>;
fn search(&mut self, ast: AST) -> Result<Vec<Task>, Error>;
}
pub mod sqlite;
pub use self::sqlite::SQLiteList;