summaryrefslogtreecommitdiffstats
path: root/imag-counter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-09-06 11:03:55 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-08 13:56:51 +0200
commitd5d83400fab342df1f658ab55cb15ebab4481eee (patch)
treeb615a5ff2d86397b18958bef575adcc27f4bcb69 /imag-counter
parent198170cf57bdd587019fc4105046991acf776a41 (diff)
imag-counter: Use utils to map over Err/Ok
Diffstat (limited to 'imag-counter')
-rw-r--r--imag-counter/src/list.rs6
-rw-r--r--imag-counter/src/main.rs33
2 files changed, 10 insertions, 29 deletions
diff --git a/imag-counter/src/list.rs b/imag-counter/src/list.rs
index 0c16c019..d18ae9b1 100644
--- a/imag-counter/src/list.rs
+++ b/imag-counter/src/list.rs
@@ -1,5 +1,5 @@
use libimagrt::runtime::Runtime;
-use libimagerror::trace::trace_error;
+use libimagerror::trace::{MapErrTrace, trace_error};
use libimagcounter::counter::Counter;
pub fn list(rt: &Runtime) {
@@ -25,11 +25,11 @@ pub fn list(rt: &Runtime) {
println!("{} - {} {}", name.unwrap(), value.unwrap(), unit.unwrap());
}
})
- .map_err(|e| trace_error(&e))
+ .map_err_trace()
.ok();
}
})
- .map_err(|e| trace_error(&e))
+ .map_err_trace()
});
}
diff --git a/imag-counter/src/main.rs b/imag-counter/src/main.rs
index 304bbb5e..c83bba0a 100644
--- a/imag-counter/src/main.rs
+++ b/imag-counter/src/main.rs
@@ -27,8 +27,9 @@ use std::str::FromStr;
use libimagrt::setup::generate_runtime_setup;
use libimagcounter::counter::Counter;
-use libimagerror::trace::{trace_error, trace_error_exit};
+use libimagerror::trace::MapErrTrace;
use libimagutil::key_value_split::IntoKeyValue;
+use libimagutil::info_result::*;
mod create;
mod delete;
@@ -73,30 +74,15 @@ fn main() {
match action {
Action::Inc => {
Counter::load(String::from(name), rt.store())
- .map(|mut counter| {
- match counter.inc() {
- Err(e) => trace_error_exit(&e, 1),
- Ok(_) => info!("Ok"),
- }
- })
+ .map(|mut c| c.inc().map_err_trace_exit(1).map_info_str("Ok"))
},
Action::Dec => {
Counter::load(String::from(name), rt.store())
- .map(|mut counter| {
- match counter.dec() {
- Err(e) => trace_error_exit(&e, 1),
- Ok(_) => info!("Ok"),
- }
- })
+ .map(|mut c| c.dec().map_err_trace_exit(1).map_info_str("Ok"))
},
Action::Reset => {
Counter::load(String::from(name), rt.store())
- .map(|mut counter| {
- match counter.reset() {
- Err(e) => trace_error_exit(&e, 1),
- Ok(_) => info!("Ok"),
- }
- })
+ .map(|mut c| c.reset().map_err_trace_exit(1).map_info_str("Ok"))
},
Action::Set => {
let kv = String::from(name).into_kv();
@@ -112,15 +98,10 @@ fn main() {
}
let value : i64 = value.unwrap();
Counter::load(String::from(key), rt.store())
- .map(|mut counter| {
- match counter.set(value) {
- Err(e) => trace_error_exit(&e, 1),
- Ok(_) => info!("Ok"),
- }
- })
+ .map(|mut c| c.set(value).map_err_trace_exit(1).map_info_str("Ok"))
},
}
- .map_err(|e| trace_error(&e))
+ .map_err_trace()
.ok();
},
|name| {