summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs10
-rw-r--r--src/lock.rs7
2 files changed, 11 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0c873be..0a0fc09 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,6 @@
+#![warn(clippy::pedantic)]
+#![warn(clippy::nursery)]
+
use std::any::type_name;
use std::fmt::{self, Debug};
use std::marker::PhantomData;
@@ -26,11 +29,12 @@ impl Debug for ThreadKey {
}
impl ThreadKey {
- /// Get the current thread's `ThreadKey, if it's not already taken.
+ /// Get the current thread's `ThreadKey`, if it's not already taken.
///
/// The first time this is called, it will successfully return a
/// `ThreadKey`. However, future calls to this function will return
/// [`None`], unless the key is dropped or unlocked first.
+ #[must_use]
pub fn lock() -> Option<Self> {
KEY.get_or_default().try_lock().map(|key| Self {
phantom: PhantomData,
@@ -42,7 +46,7 @@ impl ThreadKey {
///
/// After this method is called, a call to [`ThreadKey::lock`] will return
/// this `ThreadKey`.
- pub fn unlock(key: ThreadKey) {
- drop(key)
+ pub fn unlock(key: Self) {
+ drop(key);
}
}
diff --git a/src/lock.rs b/src/lock.rs
index fb74f25..5a6315d 100644
--- a/src/lock.rs
+++ b/src/lock.rs
@@ -12,7 +12,7 @@ pub struct Key<'a> {
}
impl<'a> Key<'a> {
- fn new(lock: &'a Lock) -> Self {
+ const fn new(lock: &'a Lock) -> Self {
Self { lock }
}
}
@@ -26,6 +26,7 @@ impl<'a> Drop for Key<'a> {
impl Lock {
/// Create a new unlocked `Lock`.
+ #[must_use]
pub const fn new() -> Self {
Self {
is_locked: AtomicBool::new(false),
@@ -52,10 +53,10 @@ impl Lock {
/// means the program no longer has a reference to the key, but it has not
/// been dropped.
unsafe fn force_unlock(&self) {
- self.is_locked.store(false, Ordering::Release)
+ self.is_locked.store(false, Ordering::Release);
}
pub fn unlock(key: Key) {
- drop(key)
+ drop(key);
}
}