Remove the most ugly parts from the lib
This commit is contained in:
parent
0752058cf5
commit
b12974043d
2 changed files with 18 additions and 18 deletions
|
@ -5,7 +5,6 @@ use task::Task;
|
|||
use result::Result;
|
||||
|
||||
pub fn get_todo_iterator(store: &Store) -> Result<TaskIterator> {
|
||||
|
||||
store.retrieve_for_module("todo/taskwarrior")
|
||||
.map(|iter| TaskIterator::new(store, iter))
|
||||
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||
|
@ -38,14 +37,13 @@ impl<'a> TaskIterator<'a> {
|
|||
iditer: iditer,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<'a> Iterator for TaskIterator<'a> {
|
||||
type Item = Result<Task<'a>>;
|
||||
|
||||
fn next(&mut self) -> Option<Result<Task<'a>>> {
|
||||
self.iditer
|
||||
.next()
|
||||
.map(|id| Task::from_storeid(self.store, id))
|
||||
self.iditer.next().map(|id| Task::from_storeid(self.store, id))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,21 @@ pub struct Task<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Task<'a> {
|
||||
|
||||
/// Concstructs a new `Task` with a `FileLockEntry`
|
||||
pub fn new(fle : FileLockEntry<'a>) -> Task<'a> {
|
||||
Task {
|
||||
flentry : fle
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// A trait to get a `libimagtodo::task::Task` out of the implementing object.
|
||||
/// This Task struct is merely a wrapper for a `FileLockEntry`, therefore the function name
|
||||
/// `into_filelockentry`.
|
||||
pub trait IntoTask<'a> {
|
||||
|
||||
/// # Usage
|
||||
/// ```ignore
|
||||
/// use std::io::stdin;
|
||||
|
@ -44,42 +47,41 @@ pub trait IntoTask<'a> {
|
|||
/// }
|
||||
/// ```
|
||||
fn into_filelockentry(self, store : &'a Store) -> Result<Task<'a>>;
|
||||
|
||||
}
|
||||
|
||||
impl<'a> IntoTask<'a> for TTask {
|
||||
|
||||
fn into_filelockentry(self, store : &'a Store) -> Result<Task<'a>> {
|
||||
let uuid = self.uuid();
|
||||
let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid();
|
||||
|
||||
match store.retrieve(store_id) {
|
||||
Err(e) => {
|
||||
return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||
},
|
||||
Err(e) => return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))),
|
||||
Ok(mut fle) => {
|
||||
{
|
||||
let mut header = fle.get_header_mut();
|
||||
match header.read("todo") {
|
||||
Ok(None) => {
|
||||
match header.set("todo", Value::Table(BTreeMap::new())) {
|
||||
Ok(_) => { },
|
||||
Err(e) => {
|
||||
if let Err(e) = header.set("todo", Value::Table(BTreeMap::new())) {
|
||||
return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Some(_)) => { }
|
||||
Err(e) => {
|
||||
return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||
}
|
||||
}
|
||||
match header.set("todo.uuid", Value::String(format!("{}",uuid))) {
|
||||
Ok(_) => { },
|
||||
Err(e) => {
|
||||
|
||||
if let Err(e) = header.set("todo.uuid", Value::String(format!("{}",uuid))) {
|
||||
return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If none of the errors above have returned the function, everything is fine
|
||||
Ok(Task { flentry : fle } )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue