summaryrefslogtreecommitdiffstats
path: root/bin/domain
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-11-04 22:36:35 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-11-06 14:48:49 +0100
commit17913ae3fd5422f2be3a77064ac107ceaf0cb10a (patch)
treedab101987e96f856987bae81352df21cfcebd91b /bin/domain
parent1321f49428b1d77611c5722733e5abd646026948 (diff)
Optimize implementation: Less matches
This patch simplifies the code to be not three nested matches but rather one match and then some function chaining. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin/domain')
-rw-r--r--bin/domain/imag-habit/src/main.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs
index 629afa10..7aa49664 100644
--- a/bin/domain/imag-habit/src/main.rs
+++ b/bin/domain/imag-habit/src/main.rs
@@ -69,6 +69,7 @@ use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
use libimaginteraction::ask::ask_bool;
+use libimagutil::debug_result::DebugResult;
mod ui;
@@ -115,20 +116,16 @@ fn create(rt: &Runtime) {
let date = scmd.value_of("create-date").unwrap(); // safe by clap
let parsedate = |d, pname| match kairos_parse(d).map_err_trace_exit_unwrap(1) {
- Parsed::TimeType(tt) => match tt.calculate() {
- Ok(tt) => match tt.get_moment() {
- Some(mom) => mom.date(),
- None => {
- debug!("TimeType yielded: '{:?}'", tt);
- error!("Error: '{}' parameter does not yield a point in time", pname);
- exit(1);
- },
- },
- Err(e) => {
- error!("Error: '{:?}'", e);
- exit(1);
- }
- },
+ Parsed::TimeType(tt) => tt.calculate()
+ .map_dbg(|y| format!("TimeType yielded: '{:?}'", y))
+ .map_err_trace_exit_unwrap(1)
+ .get_moment()
+ .ok_or_else(|| {
+ error!("Error: '{}' parameter does not yield a point in time", pname);
+ exit(1)
+ })
+ .unwrap() // safe by above
+ .date(),
_ => {
error!("Error: '{}' parameter does not yield a point in time", pname);
exit(1);