From 2c11acabd9a8c104fa564cca480088c11c9e8af9 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 7 Jun 2018 16:07:08 +0200 Subject: Use {} instead of {:?} where possible Most notably, for command errors, this will print a human-readable error message instead of just the name of the enum. --- src/auth.rs | 6 +++--- src/device.rs | 26 +++++++++++++------------- src/lib.rs | 8 ++++---- src/otp.rs | 28 ++++++++++++++-------------- src/pws.rs | 6 +++--- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 8460fae..0918222 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -42,7 +42,7 @@ pub trait Authenticate { /// user.device() /// }, /// Err((device, err)) => { - /// println!("Could not authenticate as user: {:?}", err); + /// println!("Could not authenticate as user: {}", err); /// device /// }, /// }; @@ -88,7 +88,7 @@ pub trait Authenticate { /// admin.device() /// }, /// Err((device, err)) => { - /// println!("Could not authenticate as admin: {:?}", err); + /// println!("Could not authenticate as admin: {}", err); /// device /// }, /// }; @@ -277,7 +277,7 @@ impl Admin { /// admin.write_config(config); /// () /// }, - /// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), + /// Err((_, err)) => println!("Could not authenticate as admin: {}", err), /// }; /// # Ok(()) /// # } diff --git a/src/device.rs b/src/device.rs index 63a5654..326df5d 100644 --- a/src/device.rs +++ b/src/device.rs @@ -41,7 +41,7 @@ enum Model { /// user.device() /// }, /// Err((device, err)) => { -/// println!("Could not authenticate as user: {:?}", err); +/// println!("Could not authenticate as user: {}", err); /// device /// }, /// }; @@ -86,7 +86,7 @@ pub enum DeviceWrapper { /// user.device() /// }, /// Err((device, err)) => { -/// println!("Could not authenticate as user: {:?}", err); +/// println!("Could not authenticate as user: {}", err); /// device /// }, /// }; @@ -128,7 +128,7 @@ pub struct Pro {} /// user.device() /// }, /// Err((device, err)) => { -/// println!("Could not authenticate as user: {:?}", err); +/// println!("Could not authenticate as user: {}", err); /// device /// }, /// }; @@ -161,8 +161,8 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// # fn try_main() -> Result<(), CommandError> { /// let device = nitrokey::connect()?; /// match device.get_serial_number() { - /// Ok(number) => println!("serial no: {:?}", number), - /// Err(err) => println!("Could not get serial number: {:?}", err), + /// Ok(number) => println!("serial no: {}", number), + /// Err(err) => println!("Could not get serial number: {}", err), /// }; /// # Ok(()) /// # } @@ -302,7 +302,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// let device = nitrokey::connect()?; /// match device.change_admin_pin("12345678", "12345679") { /// Ok(()) => println!("Updated admin PIN."), - /// Err(err) => println!("Failed to update admin PIN: {:?}", err), + /// Err(err) => println!("Failed to update admin PIN: {}", err), /// }; /// # Ok(()) /// # } @@ -338,7 +338,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// let device = nitrokey::connect()?; /// match device.change_user_pin("123456", "123457") { /// Ok(()) => println!("Updated admin PIN."), - /// Err(err) => println!("Failed to update admin PIN: {:?}", err), + /// Err(err) => println!("Failed to update admin PIN: {}", err), /// }; /// # Ok(()) /// # } @@ -374,7 +374,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// let device = nitrokey::connect()?; /// match device.unlock_user_pin("12345678", "123456") { /// Ok(()) => println!("Unlocked user PIN."), - /// Err(err) => println!("Failed to unlock user PIN: {:?}", err), + /// Err(err) => println!("Failed to unlock user PIN: {}", err), /// }; /// # Ok(()) /// # } @@ -408,7 +408,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// let device = nitrokey::connect()?; /// match device.lock() { /// Ok(()) => println!("Locked the Nitrokey device."), - /// Err(err) => println!("Could not lock the Nitrokey device: {:?}", err), + /// Err(err) => println!("Could not lock the Nitrokey device: {}", err), /// }; /// # Ok(()) /// # } @@ -430,7 +430,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp { /// /// match nitrokey::connect() { /// Ok(device) => do_something(device), -/// Err(err) => println!("Could not connect to a Nitrokey: {:?}", err), +/// Err(err) => println!("Could not connect to a Nitrokey: {}", err), /// } /// ``` pub fn connect() -> Result { @@ -537,7 +537,7 @@ impl Storage { /// let device = nitrokey::Storage::connect()?; /// match device.enable_encrypted_volume("123456") { /// Ok(()) => println!("Enabled the encrypted volume."), - /// Err(err) => println!("Could not enable the encrypted volume: {:?}", err), + /// Err(err) => println!("Could not enable the encrypted volume: {}", err), /// }; /// # Ok(()) /// # } @@ -571,11 +571,11 @@ impl Storage { /// match device.disable_encrypted_volume() { /// Ok(()) => println!("Disabled the encrypted volume."), /// Err(err) => { - /// println!("Could not disable the encrypted volume: {:?}", err); + /// println!("Could not disable the encrypted volume: {}", err); /// }, /// }; /// }, - /// Err(err) => println!("Could not enable the encrypted volume: {:?}", err), + /// Err(err) => println!("Could not enable the encrypted volume: {}", err), /// }; /// # Ok(()) /// # } diff --git a/src/lib.rs b/src/lib.rs index aa44706..df16ea7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,10 +47,10 @@ //! Ok(admin) => { //! match admin.write_hotp_slot(slot_data, 0) { //! Ok(()) => println!("Successfully wrote slot."), -//! Err(err) => println!("Could not write slot: {:?}", err), +//! Err(err) => println!("Could not write slot: {}", err), //! } //! }, -//! Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), +//! Err((_, err)) => println!("Could not authenticate as admin: {}", err), //! } //! # Ok(()) //! # } @@ -65,8 +65,8 @@ //! # fn try_main() -> Result<(), (CommandError)> { //! let device = nitrokey::connect()?; //! match device.get_hotp_code(1) { -//! Ok(code) => println!("Generated HOTP code: {:?}", code), -//! Err(err) => println!("Could not generate HOTP code: {:?}", err), +//! Ok(code) => println!("Generated HOTP code: {}", code), +//! Err(err) => println!("Could not generate HOTP code: {}", err), //! } //! # Ok(()) //! # } diff --git a/src/otp.rs b/src/otp.rs index e43b1c8..00a5e5e 100644 --- a/src/otp.rs +++ b/src/otp.rs @@ -35,10 +35,10 @@ pub trait ConfigureOtp { /// Ok(admin) => { /// match admin.write_hotp_slot(slot_data, 0) { /// Ok(()) => println!("Successfully wrote slot."), - /// Err(err) => println!("Could not write slot: {:?}", err), + /// Err(err) => println!("Could not write slot: {}", err), /// } /// }, - /// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), + /// Err((_, err)) => println!("Could not authenticate as admin: {}", err), /// } /// # Ok(()) /// # } @@ -71,10 +71,10 @@ pub trait ConfigureOtp { /// Ok(admin) => { /// match admin.write_totp_slot(slot_data, 30) { /// Ok(()) => println!("Successfully wrote slot."), - /// Err(err) => println!("Could not write slot: {:?}", err), + /// Err(err) => println!("Could not write slot: {}", err), /// } /// }, - /// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), + /// Err((_, err)) => println!("Could not authenticate as admin: {}", err), /// } /// # Ok(()) /// # } @@ -103,10 +103,10 @@ pub trait ConfigureOtp { /// Ok(admin) => { /// match admin.erase_hotp_slot(1) { /// Ok(()) => println!("Successfully erased slot."), - /// Err(err) => println!("Could not erase slot: {:?}", err), + /// Err(err) => println!("Could not erase slot: {}", err), /// } /// }, - /// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), + /// Err((_, err)) => println!("Could not authenticate as admin: {}", err), /// } /// # Ok(()) /// # } @@ -133,10 +133,10 @@ pub trait ConfigureOtp { /// Ok(admin) => { /// match admin.erase_totp_slot(1) { /// Ok(()) => println!("Successfully erased slot."), - /// Err(err) => println!("Could not erase slot: {:?}", err), + /// Err(err) => println!("Could not erase slot: {}", err), /// } /// }, - /// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err), + /// Err((_, err)) => println!("Could not authenticate as admin: {}", err), /// } /// # Ok(()) /// # } @@ -200,9 +200,9 @@ pub trait GenerateOtp { /// # fn try_main() -> Result<(), CommandError> { /// let device = nitrokey::connect()?; /// match device.get_hotp_slot_name(1) { - /// Ok(name) => println!("HOTP slot 1: {:?}", name), + /// Ok(name) => println!("HOTP slot 1: {}", name), /// Err(CommandError::SlotNotProgrammed) => println!("HOTP slot 1 not programmed"), - /// Err(err) => println!("Could not get slot name: {:?}", err), + /// Err(err) => println!("Could not get slot name: {}", err), /// }; /// # Ok(()) /// # } @@ -229,9 +229,9 @@ pub trait GenerateOtp { /// # fn try_main() -> Result<(), CommandError> { /// let device = nitrokey::connect()?; /// match device.get_totp_slot_name(1) { - /// Ok(name) => println!("TOTP slot 1: {:?}", name), + /// Ok(name) => println!("TOTP slot 1: {}", name), /// Err(CommandError::SlotNotProgrammed) => println!("TOTP slot 1 not programmed"), - /// Err(err) => println!("Could not get slot name: {:?}", err), + /// Err(err) => println!("Could not get slot name: {}", err), /// }; /// # Ok(()) /// # } @@ -261,7 +261,7 @@ pub trait GenerateOtp { /// # fn try_main() -> Result<(), CommandError> { /// let device = nitrokey::connect()?; /// let code = device.get_hotp_code(1)?; - /// println!("Generated HOTP code on slot 1: {:?}", code); + /// println!("Generated HOTP code on slot 1: {}", code); /// # Ok(()) /// # } /// ``` @@ -304,7 +304,7 @@ pub trait GenerateOtp { /// } else { /// device.set_time(time as u64); /// let code = device.get_totp_code(1)?; - /// println!("Generated TOTP code on slot 1: {:?}", code); + /// println!("Generated TOTP code on slot 1: {}", code); /// } /// # Ok(()) /// # } diff --git a/src/pws.rs b/src/pws.rs index 17f247e..c20fe9d 100644 --- a/src/pws.rs +++ b/src/pws.rs @@ -88,7 +88,7 @@ pub trait GetPasswordSafe { /// use_password_safe(&pws); /// device.lock()?; /// }, - /// Err(err) => println!("Could not open the password safe: {:?}", err), + /// Err(err) => println!("Could not open the password safe: {}", err), /// }; /// # Ok(()) /// # } @@ -177,7 +177,7 @@ impl<'a> PasswordSafe<'a> { /// let password = pws.get_slot_login(0)?; /// println!("Credentials for {}: login {}, password {}", name, login, password); /// }, - /// Err(err) => println!("Could not open the password safe: {:?}", err), + /// Err(err) => println!("Could not open the password safe: {}", err), /// }; /// # Ok(()) /// # } @@ -313,7 +313,7 @@ impl<'a> PasswordSafe<'a> { /// let pws = device.get_password_safe("123456")?; /// match pws.erase_slot(0) { /// Ok(()) => println!("Erased slot 0."), - /// Err(err) => println!("Could not erase slot 0: {:?}", err), + /// Err(err) => println!("Could not erase slot 0: {}", err), /// }; /// # Ok(()) /// # } -- cgit v1.2.3