From bd085b0ead496f9071d23617ee78975b0e039cad Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 3 Aug 2016 11:33:13 +0200 Subject: [PATCH 1/4] Replace unwrap() with match --- imag-store/src/retrieve.rs | 7 ++----- imag-store/src/update.rs | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index e7ad75db..f9f45993 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -12,11 +12,8 @@ pub fn retrieve(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = build_entry_path(rt.store(), id); - if path.is_err() { - trace_error_exit(&path.unwrap_err(), 1); - } - let path = path.unwrap(); + let path = try!(build_entry_path(rt.store(), id) + .map_err(|e| trace_error_exit(&e, 1))); debug!("path = {:?}", path); rt.store() diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index cee83f84..9959ec09 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -12,11 +12,10 @@ pub fn update(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = build_entry_path(rt.store(), id); - if path.is_err() { - trace_error_exit(&path.unwrap_err(), 1); - } - let path = path.unwrap(); + let path = match build_entry_path(rt.store(), id) { + Err(e) => trace_error_exit(&e, 1), + Ok(p) => p, + }; rt.store() .retrieve(path) From 84e33c07e68d399530b8d2a1c1d02f343bc891f0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 3 Aug 2016 11:33:55 +0200 Subject: [PATCH 2/4] Replace unwrap() with try!() --- imag-store/src/delete.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index d935ea9f..46626816 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -10,11 +10,8 @@ pub fn delete(rt: &Runtime) { .map(|sub| { sub.value_of("id") .map(|id| { - let path = build_entry_path(rt.store(), id); - if path.is_err() { - trace_error_exit(&path.unwrap_err(), 1); - } - let path = path.unwrap(); + let path = try!(build_entry_path(rt.store(), id) + .map_err(|e| trace_error_exit(&e, 1))); debug!("Deleting file at {:?}", id); rt.store() From 0f13fc38c0227b316eed5f569b92e4f5b1ad733a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 3 Aug 2016 11:34:58 +0200 Subject: [PATCH 3/4] Replace unwrap() with match --- imag-store/src/create.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index e02328e0..7329df3f 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -36,11 +36,10 @@ pub fn create(rt: &Runtime) { exit(1); } - let path = build_entry_path(rt.store(), path.unwrap()); - if path.is_err() { - trace_error_exit(&path.unwrap_err(), 1); - } - let path = path.unwrap(); + let path = match build_entry_path(rt.store(), path.unwrap()) { + Err(e) => trace_error_exit(&e, 1), + Ok(p) => p, + }; debug!("path = {:?}", path); if scmd.subcommand_matches("entry").is_some() { From 13945ab352c630a0847ed0667dc1471186f38c0e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 3 Aug 2016 11:36:40 +0200 Subject: [PATCH 4/4] Replace unwrap() with match --- imag-store/src/get.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/imag-store/src/get.rs b/imag-store/src/get.rs index 58abe3f7..3e33ac2b 100644 --- a/imag-store/src/get.rs +++ b/imag-store/src/get.rs @@ -10,11 +10,10 @@ pub fn get(rt: &Runtime) { .map(|scmd| { scmd.value_of("id") .map(|id| { - let path = build_entry_path(rt.store(), id); - if path.is_err() { - trace_error_exit(&path.unwrap_err(), 1); - } - let path = path.unwrap(); + let path = match build_entry_path(rt.store(), id) { + Err(e) => trace_error_exit(&e, 1), + Ok(p) => p, + }; debug!("path = {:?}", path); match rt.store().get(path) {