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