aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-07-14 21:43:37 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-07-14 21:43:37 +0200
commitd0f517eec5fbeb402a42eb2b23ca13fc85f1bc98 (patch)
tree1bba179f71828cb9e0004c82ed991fe22cddf3f2 /src/lib.rs
parentcf460cbb5e616d12f5e6b1f64acddf3ec0e7b087 (diff)
parentf1e83eb81879412e1de9898238ba58289bb6cb24 (diff)
downloadnitrokey-rs-d0f517eec5fbeb402a42eb2b23ca13fc85f1bc98.tar.gz
nitrokey-rs-d0f517eec5fbeb402a42eb2b23ca13fc85f1bc98.tar.bz2
Merge branch 'poison-error' into next
This patch series refactors the Error enum and ensures that it is Send, Sync and 'static. This makes sure that it is compatible with the anyhow crate. To achieve this, we drop the RandError variant and remove the sync::PoisonError value from the PoisonError variant.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs11
1 files changed, 4 insertions, 7 deletions
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<sync::MutexGuard<'static, Manager>, Error> {
/// [`ConcurrentAccessError`]: struct.Error.html#variant.ConcurrentAccessError
/// [`Manager`]: struct.Manager.html
pub fn force_take() -> Result<sync::MutexGuard<'static, Manager>, 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.