diff options
author | Daniel Mueller <deso@posteo.net> | 2019-07-14 15:44:16 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-07-14 15:44:16 -0700 |
commit | ba80a9087cc2ca91e81fdb9427213421567419ea (patch) | |
tree | 680c1200ff21f3b8bbfb6939e9a098c1d07bfa52 | |
parent | 4094d8d0592c507f322681b070b0fa0fefccd673 (diff) | |
download | nitrocli-ba80a9087cc2ca91e81fdb9427213421567419ea.tar.gz nitrocli-ba80a9087cc2ca91e81fdb9427213421567419ea.tar.bz2 |
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.
-rw-r--r-- | nitrocli/src/commands.rs | 4 |
1 files 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> } } - 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<T: GenerateOtp>(slot: u8, algorithm: args::OtpAlgorithm, device: &T) fn get_unix_timestamp() -> Result<u64> { 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()) } |