From ba80a9087cc2ca91e81fdb9427213421567419ea Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 14 Jul 2019 15:44:16 -0700 Subject: Use map_err over or_else to convert errors This patch replaces two cases where we use Result::or_else over the more idiomatic (and shorter) Result::map_err for converting errors. --- nitrocli/src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 8db5cd8..208a0ec 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -80,7 +80,7 @@ fn get_storage_device(ctx: &mut args::ExecCtx<'_>) -> Result } } - nitrokey::Storage::connect().or_else(|_| Err(Error::from("Nitrokey Storage device not found"))) + nitrokey::Storage::connect().map_err(|_| Error::from("Nitrokey Storage device not found")) } /// Open the password safe on the given device. @@ -531,7 +531,7 @@ fn get_otp(slot: u8, algorithm: args::OtpAlgorithm, device: &T) fn get_unix_timestamp() -> Result { time::SystemTime::now() .duration_since(time::UNIX_EPOCH) - .or_else(|_| Err(Error::from("Current system time is before the Unix epoch"))) + .map_err(|_| Error::from("Current system time is before the Unix epoch")) .map(|duration| duration.as_secs()) } -- cgit v1.2.3