diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-27 13:31:36 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-27 13:31:36 +0000 |
commit | a30562638aed90d113739bb36dd6814f6cf7ace2 (patch) | |
tree | 3baf09f049b0cc7574d919c2dead8b837492e1d4 | |
parent | 04220982d4808c402b1a5cdda2b83e81f099a1ad (diff) | |
download | nitrokey-rs-a30562638aed90d113739bb36dd6814f6cf7ace2.tar.gz nitrokey-rs-a30562638aed90d113739bb36dd6814f6cf7ace2.tar.bz2 |
Remove the Result typedef
Many of our functions do not return a Result<_, Error>, but for example
a Result<_, (Device, Error)>. We only use the typedef in one function,
but it makes the other functions more complicated as we have to use
result::Result (if crate::Result is imported). Therefore, this patch
removes the typedef. Applications or libraries can still redefine it if
they want to.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/error.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 4 |
3 files changed, 3 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b9983ed..271230d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT - Introduce `DEFAULT_ADMIN_PIN` and `DEFAULT_USER_PIN` constants. - Refactor the error handling code: - Implement `std::error::Error` for `CommandError`. - - Add the `Error` enum and the `Result` typedef. + - Add the `Error` enum. - Add the `LibraryError` enum and move the library error variants from `CommandError` to `LibraryError`. - Add the `CommunicationError` enum and move the communication error variants diff --git a/src/error.rs b/src/error.rs index 1b36975..5c8c52e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,6 @@ use std::error; use std::fmt; use std::os::raw; -use std::result; use std::str; use crate::device; @@ -100,9 +99,6 @@ impl fmt::Display for Error { } } -/// A result returned by the nitrokey crate. -pub type Result<T> = result::Result<T, Error>; - /// An error reported by the Nitrokey device in the response packet. #[derive(Clone, Copy, Debug, PartialEq)] pub enum CommandError { @@ -107,7 +107,7 @@ pub use crate::device::{ connect, connect_model, Device, DeviceWrapper, Model, Pro, SdCardData, Storage, StorageProductionInfo, StorageStatus, VolumeMode, VolumeStatus, }; -pub use crate::error::{CommandError, CommunicationError, Error, LibraryError, Result}; +pub use crate::error::{CommandError, CommunicationError, Error, LibraryError}; pub use crate::otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData}; pub use crate::pws::{GetPasswordSafe, PasswordSafe, SLOT_COUNT}; pub use crate::util::LogLevel; @@ -186,7 +186,7 @@ pub fn set_log_level(level: LogLevel) { /// ``` /// /// [`Utf8Error`]: enum.Error.html#variant.Utf8Error -pub fn get_library_version() -> Result<Version> { +pub fn get_library_version() -> Result<Version, Error> { // NK_get_library_version returns a static string, so we don’t have to free the pointer. let git = unsafe { nitrokey_sys::NK_get_library_version() }; let git = if git.is_null() { |