From fad981a40f7051e627460f62bf7f3409dc634f58 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:43:58 +0200 Subject: [PATCH 1/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagdiary/Cargo.toml | 2 +- libimagdiary/src/config.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libimagdiary/Cargo.toml b/libimagdiary/Cargo.toml index 0f891959..751530f8 100644 --- a/libimagdiary/Cargo.toml +++ b/libimagdiary/Cargo.toml @@ -18,7 +18,7 @@ chrono = "0.2" log = "0.3" semver = "0.5" toml = "0.4.*" -toml-query = "0.2.*" +toml-query = "0.3.*" regex = "0.1" itertools = "0.5" diff --git a/libimagdiary/src/config.rs b/libimagdiary/src/config.rs index a341b24c..c2a6a980 100644 --- a/libimagdiary/src/config.rs +++ b/libimagdiary/src/config.rs @@ -27,7 +27,7 @@ pub fn get_default_diary_name(rt: &Runtime) -> Option { get_diary_config_section(rt) .and_then(|config| { match config.read(&String::from("default_diary")) { - Ok(&Value::String(ref s)) => Some(s.clone()), + Ok(Some(&Value::String(ref s))) => Some(s.clone()), _ => None, } }) @@ -36,5 +36,8 @@ pub fn get_default_diary_name(rt: &Runtime) -> Option { pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> { rt.config() .map(|config| config.config()) - .and_then(|config| config.read(&String::from("diary")).ok()) + .and_then(|config| match config.read(&String::from("diary")) { + Ok(x) => x, + Err(_) => None, + }) } From 19e8be9f9b85e6ac90c456086d609697f220c2dd Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:45:13 +0200 Subject: [PATCH 2/7] Update toml-query: 0.2.0 -> 0.3.0 --- imag-todo/Cargo.toml | 2 +- imag-todo/src/main.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/imag-todo/Cargo.toml b/imag-todo/Cargo.toml index 9a32ce4d..bc11fc5e 100644 --- a/imag-todo/Cargo.toml +++ b/imag-todo/Cargo.toml @@ -21,7 +21,7 @@ semver = "0.5.1" serde_json = "0.8.3" task-hookrs = "0.2.2" toml = "0.4.*" -toml-query = "0.2.*" +toml-query = "0.3.*" is-match = "0.1.*" version = "2.0.1" diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 4d6396bc..b9bd8872 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -103,11 +103,15 @@ fn list(rt: &Runtime) { // filter out the ones were we can read the uuid let uuids : Vec<_> = iter.filter_map(|t| match t { Ok(v) => match v.get_header().read(&String::from("todo.uuid")) { - Ok(&Value::String(ref u)) => Some(u.clone()), - Ok(_) => { + Ok(Some(&Value::String(ref u))) => Some(u.clone()), + Ok(Some(_)) => { warn!("Header type error"); None }, + Ok(None) => { + warn!("Header missing field"); + None + }, Err(e) => { if !no_identifier(&e) { trace_error(&e); From bddc79efaa7140661a8ee95495b71c92db99796e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:48:01 +0200 Subject: [PATCH 3/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagcounter/Cargo.toml | 2 +- libimagcounter/src/counter.rs | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libimagcounter/Cargo.toml b/libimagcounter/Cargo.toml index 4298a935..3f1f52ce 100644 --- a/libimagcounter/Cargo.toml +++ b/libimagcounter/Cargo.toml @@ -16,7 +16,7 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" toml = "0.4.*" -toml-query = "0.2.*" +toml-query = "0.3.*" semver = "0.5" [dependencies.libimagstore] diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs index 9c699018..7b6c1d3c 100644 --- a/libimagcounter/src/counter.rs +++ b/libimagcounter/src/counter.rs @@ -117,7 +117,7 @@ impl<'a> Counter<'a> { let mut header = self.fle.deref_mut().get_header_mut(); let query = String::from("counter.value"); match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { - &Value::Integer(i) => { + Some(&Value::Integer(i)) => { header.set(&query, Value::Integer(i + 1)) .map_err_into(CEK::StoreWriteError) .map(|_| ()) @@ -130,7 +130,7 @@ impl<'a> Counter<'a> { let mut header = self.fle.deref_mut().get_header_mut(); let query = String::from("counter.value"); match try!(header.read(&query).map_err_into(CEK::StoreReadError)) { - &Value::Integer(i) => { + Some(&Value::Integer(i)) => { header.set(&query, Value::Integer(i - 1)) .map_err_into(CEK::StoreWriteError) .map(|_| ()) @@ -152,15 +152,17 @@ impl<'a> Counter<'a> { pub fn name(&self) -> Result { self.read_header_at("counter.name", |v| match v { - &Value::String(ref s) => Ok(s.clone()), - _ => Err(CEK::HeaderTypeError.into_error()), + Some(&Value::String(ref s)) => Ok(s.clone()), + Some(_) => Err(CEK::HeaderTypeError.into_error()), + _ => Err(CEK::StoreReadError.into_error()), }) } pub fn value(&self) -> Result { self.read_header_at("counter.value", |v| match v { - &Value::Integer(i) => Ok(i), - _ => Err(CEK::HeaderTypeError.into_error()), + Some(&Value::Integer(i)) => Ok(i), + Some(_) => Err(CEK::HeaderTypeError.into_error()), + _ => Err(CEK::StoreReadError.into_error()), }) } @@ -170,13 +172,14 @@ impl<'a> Counter<'a> { pub fn read_unit(&self) -> Result> { self.read_header_at("counter.unit", |s| match s { - &Value::String(ref s) => Ok(Some(CounterUnit::new(s.clone()))), - _ => Err(CEK::HeaderTypeError.into_error()), + Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))), + Some(_) => Err(CEK::HeaderTypeError.into_error()), + _ => Err(CEK::StoreReadError.into_error()), }) } fn read_header_at(&self, name: &str, f: F) -> Result - where F: FnOnce(&Value) -> Result + where F: FnOnce(Option<&Value>) -> Result { self.fle From 218977ae17d57c3cbda5ac913477f60bbf7dd5af Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:51:26 +0200 Subject: [PATCH 4/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagentrycategory/Cargo.toml | 2 +- libimagentrycategory/src/category.rs | 15 ++++----------- libimagentrycategory/src/register.rs | 11 ++++++----- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/libimagentrycategory/Cargo.toml b/libimagentrycategory/Cargo.toml index 36035cf8..8e996442 100644 --- a/libimagentrycategory/Cargo.toml +++ b/libimagentrycategory/Cargo.toml @@ -16,7 +16,7 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.3" toml = "0.4" -toml-query = "0.2" +toml-query = "0.3" is-match = "0.1" [dev-dependencies] diff --git a/libimagentrycategory/src/category.rs b/libimagentrycategory/src/category.rs index 89763913..1e77495e 100644 --- a/libimagentrycategory/src/category.rs +++ b/libimagentrycategory/src/category.rs @@ -88,23 +88,16 @@ impl EntryCategory for Entry { } .map_err_into(CEK::HeaderReadError), - Ok(&Value::String(ref s)) => Ok(Some(s.clone().into())), + Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())), + Ok(None) => Err(CEK::StoreReadError.into_error()).map_err_into(CEK::HeaderReadError), Ok(_) => Err(CEK::TypeError.into_error()).map_err_into(CEK::HeaderReadError), } } fn has_category(&self) -> Result { - let res = self.get_header().read(&String::from("category.value")); - if res.is_err() { - let res = res.unwrap_err(); - match res.kind() { - &TQEK::IdentifierNotFoundInDocument(_) => Ok(false), - _ => Err(res), - } + self.get_header().read(&String::from("category.value")) .map_err_into(CEK::HeaderReadError) - } else { - Ok(true) - } + .map(|e| e.is_some()) } } diff --git a/libimagentrycategory/src/register.rs b/libimagentrycategory/src/register.rs index aa85d804..e8853631 100644 --- a/libimagentrycategory/src/register.rs +++ b/libimagentrycategory/src/register.rs @@ -198,9 +198,10 @@ mod tests { assert!(header_field.is_ok(), format!("Expected Ok(_), got: {:?}", header_field)); let header_field = header_field.unwrap(); - match *header_field { - Value::String(ref s) => assert_eq!(category_name, s), - _ => assert!(false, "Header field has wrong type"), + match header_field { + Some(&Value::String(ref s)) => assert_eq!(category_name, s), + Some(_) => assert!(false, "Header field has wrong type"), + None => assert!(false, "Header field not present"), } } } @@ -228,7 +229,7 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result .read(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH)) .map_err_into(CEK::HeaderReadError) { - Ok(&Value::String(ref s)) => Ok(s == name), + Ok(Some(&Value::String(ref s))) => Ok(s == name), Ok(_) => Err(CEK::TypeError.into_error()), Err(e) => Err(e).map_err_into(CEK::HeaderReadError), } @@ -279,7 +280,7 @@ impl<'a> Iterator for CategoryNameIter<'a> { .map_err_into(CEK::StoreReadError) .and_then(|fle| fle.ok_or(CEK::StoreReadError.into_error())) .and_then(|fle| match fle.get_header().read(&query) { - Ok(&Value::String(ref s)) => Ok(Category::from(s.clone())), + Ok(Some(&Value::String(ref s))) => Ok(Category::from(s.clone())), Ok(_) => Err(CEK::TypeError.into_error()), Err(e) => Err(e).map_err_into(CEK::HeaderReadError), }) From 86adb4d0648442ac6c125a3d3c9f7db252e5b08d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:53:13 +0200 Subject: [PATCH 5/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagentrydatetime/Cargo.toml | 2 +- libimagentrydatetime/src/datetime.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libimagentrydatetime/Cargo.toml b/libimagentrydatetime/Cargo.toml index 1c810e9f..119487fc 100644 --- a/libimagentrydatetime/Cargo.toml +++ b/libimagentrydatetime/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] chrono = "0.3" -toml-query = "0.2" +toml-query = "0.3" lazy_static = "0.2" toml = "0.4" diff --git a/libimagentrydatetime/src/datetime.rs b/libimagentrydatetime/src/datetime.rs index b78dac08..6e7911bf 100644 --- a/libimagentrydatetime/src/datetime.rs +++ b/libimagentrydatetime/src/datetime.rs @@ -65,9 +65,10 @@ impl EntryDate for Entry { .map_err_into(DEK::ReadDateError) .and_then(|v| { match v { - &Value::String(ref s) => s.parse::() + Some(&Value::String(ref s)) => s.parse::() .map_err_into(DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DEK::ReadDateError.into_error()), } }) } @@ -131,9 +132,10 @@ impl EntryDate for Entry { .map_err_into(DEK::ReadDateTimeRangeError) .and_then(|v| { match v { - &Value::String(ref s) => s.parse::() + Some(&Value::String(ref s)) => s.parse::() .map_err_into(DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DEK::ReadDateError.into_error()), } })); @@ -143,9 +145,10 @@ impl EntryDate for Entry { .map_err_into(DEK::ReadDateTimeRangeError) .and_then(|v| { match v { - &Value::String(ref s) => s.parse::() + Some(&Value::String(ref s)) => s.parse::() .map_err_into(DEK::DateTimeParsingError), - _ => Err(DEK::DateHeaderFieldTypeError.into_error()), + Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()), + _ => Err(DEK::ReadDateError.into_error()), } })); @@ -250,6 +253,9 @@ mod tests { assert!(hdr_field.is_ok()); let hdr_field = hdr_field.unwrap(); + assert!(hdr_field.is_some()); + let hdr_field = hdr_field.unwrap(); + match *hdr_field { Value::String(ref s) => assert_eq!("2000-01-02T03:04:05", s), _ => assert!(false, "Wrong header type"), @@ -315,7 +321,10 @@ mod tests { let hdr_field = entry.get_header().read(&DATE_HEADER_LOCATION); - assert!(hdr_field.is_err(), format!("Expected Err(_), got: {:?}", hdr_field)); + assert!(hdr_field.is_ok()); + let hdr_field = hdr_field.unwrap(); + + assert!(hdr_field.is_none()); } } From 35bffe827b2a89214d0057ebb44aa341d3c785ee Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:54:56 +0200 Subject: [PATCH 6/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagtimetrack/Cargo.toml | 2 +- libimagtimetrack/src/event.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libimagtimetrack/Cargo.toml b/libimagtimetrack/Cargo.toml index f7eaad76..7be71719 100644 --- a/libimagtimetrack/Cargo.toml +++ b/libimagtimetrack/Cargo.toml @@ -17,7 +17,7 @@ homepage = "http://imag-pim.org" filters = "0.1" chrono = "0.3" toml = "0.4" -toml-query = "0.2" +toml-query = "0.3" lazy_static = "0.2" [dependencies.libimagerror] diff --git a/libimagtimetrack/src/event.rs b/libimagtimetrack/src/event.rs index 40b6e34e..6ee2c105 100644 --- a/libimagtimetrack/src/event.rs +++ b/libimagtimetrack/src/event.rs @@ -43,13 +43,13 @@ pub trait TimeTracking { fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()>; - fn get_start_datetime(&self) -> Result; + fn get_start_datetime(&self) -> Result>; fn delete_start_datetime(&mut self) -> Result<()>; fn set_end_datetime(&mut self, dt: NaiveDateTime) -> Result<()>; - fn get_end_datetime(&self) -> Result; + fn get_end_datetime(&self) -> Result>; fn delete_end_datetime(&mut self) -> Result<()>; @@ -68,7 +68,7 @@ impl TimeTracking for Entry { .map(|_| ()) } - fn get_start_datetime(&self) -> Result { + fn get_start_datetime(&self) -> Result> { self.get_header() .read(DATE_TIME_START_HEADER_PATH) .map_err_into(TTEK::HeaderReadError) @@ -91,7 +91,7 @@ impl TimeTracking for Entry { .map(|_| ()) } - fn get_end_datetime(&self) -> Result { + fn get_end_datetime(&self) -> Result> { self.get_header() .read(DATE_TIME_END_HEADER_PATH) .map_err_into(TTEK::HeaderReadError) @@ -123,13 +123,16 @@ impl TimeTracking for Entry { } -fn header_value_to_dt(val: &Value) -> Result { +fn header_value_to_dt(val: Option<&Value>) -> Result> { match val { - &Value::String(ref s) => { + Some(&Value::String(ref s)) => { NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT) .map_err_into(TTEK::DateTimeParserError) + .map(Some) + }, - _ => Err(TTEK::HeaderFieldTypeError.into_error()) + Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()), + None => Ok(None), } } From 398332fcb240846169b15ccaab6e4d3c33fac5f8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 9 Jul 2017 21:55:49 +0200 Subject: [PATCH 7/7] Update toml-query: 0.2.0 -> 0.3.0 --- libimagtodo/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagtodo/Cargo.toml b/libimagtodo/Cargo.toml index 3f4c5bf7..791b681c 100644 --- a/libimagtodo/Cargo.toml +++ b/libimagtodo/Cargo.toml @@ -18,7 +18,7 @@ semver = "0.2" task-hookrs = "0.2.2" uuid = "0.3" toml = "0.4.*" -toml-query = "0.2.*" +toml-query = "0.3.*" is-match = "0.1.*" log = "0.3" serde_json = "0.8"