From 462fc2d9aab8f0cba680caec344e4c388e9901b1 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 11 Mar 2024 16:33:26 -0400 Subject: Documentation --- src/key.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/key.rs') diff --git a/src/key.rs b/src/key.rs index 887ac29..1cfa209 100644 --- a/src/key.rs +++ b/src/key.rs @@ -20,7 +20,7 @@ static KEY: Lazy> = Lazy::new(ThreadLocal::new); /// The key for the current thread. /// /// Only one of these exist per thread. To get the current thread's key, call -/// [`ThreadKey::lock`]. If the `ThreadKey` is dropped, it can be reobtained. +/// [`ThreadKey::get`]. If the `ThreadKey` is dropped, it can be reobtained. pub struct ThreadKey { phantom: PhantomData<*const ()>, // implement !Send and !Sync } @@ -54,21 +54,21 @@ impl ThreadKey { /// The first time this is called, it will successfully return a /// `ThreadKey`. However, future calls to this function on the same thread /// will return [`None`], unless the key is dropped or unlocked first. + /// + /// # Examples + /// + /// ``` + /// use happylock::ThreadKey; + /// + /// let key = ThreadKey::get().unwrap(); + /// ``` #[must_use] - pub fn lock() -> Option { + pub fn get() -> Option { // safety: we just acquired the lock KEY.get_or_default().try_lock().then_some(Self { phantom: PhantomData, }) } - - /// Unlocks the `ThreadKey`. - /// - /// After this method is called, a call to [`ThreadKey::lock`] will return - /// this `ThreadKey`. - pub fn unlock(self) { - drop(self); - } } /// A dumb lock that's just a wrapper for an [`AtomicBool`]. -- cgit v1.2.3