From 9f80512a11926c5ec3f869ad5e220b3b350eec9a Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 8 Jul 2020 12:18:41 +0200 Subject: Remove unused imports --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 92247d7..3fa3ae3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,8 +133,6 @@ use std::marker; use std::ptr::NonNull; use std::sync; -use nitrokey_sys; - pub use crate::auth::{Admin, Authenticate, User}; pub use crate::config::Config; pub use crate::device::{ -- cgit v1.2.1 From 98232c7bc262dd3902b8f3e299196ab9c83fb355 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 8 Jul 2020 12:08:26 +0200 Subject: Remove sync::PoisonError from Error::PoisonError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the Error::PoisonError contained the sync::PoisonError that caused the error. This is problematic as sync::PoisonError does not implement Send, making it impossible to use the Error enum with the anyhow crate. At the same time, storing the sync::PoisonError is not very useful. If a user wants to access the poisoned lock, they can call the force_take function. Therefore we remove the sync::PoisonError value from the Error:: PoisonError variant. This also allows us to simplify the From> and From> implementations as we no longer need to know the type of the mutex that caused the error. For more information, see this thread: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C68ed0f3f-d98f-63bc-04d2-81b6d6cde560%40posteo.net%3E --- src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 3fa3ae3..5b72d63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -470,13 +470,10 @@ pub fn take() -> Result, Error> { /// [`ConcurrentAccessError`]: struct.Error.html#variant.ConcurrentAccessError /// [`Manager`]: struct.Manager.html pub fn force_take() -> Result, Error> { - match take() { - Ok(guard) => Ok(guard), - Err(err) => match err { - Error::PoisonError(err) => Ok(err.into_inner()), - err => Err(err), - }, - } + MANAGER.try_lock().or_else(|err| match err { + sync::TryLockError::Poisoned(err) => Ok(err.into_inner()), + sync::TryLockError::WouldBlock => Err(Error::ConcurrentAccessError), + }) } /// List all connected Nitrokey devices. -- cgit v1.2.1