diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-11 16:33:26 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-11 16:33:26 -0400 |
| commit | 462fc2d9aab8f0cba680caec344e4c388e9901b1 (patch) | |
| tree | 6b401c5ed4920c2ec8093d5c49976fe0b72573c2 /src/key.rs | |
| parent | 5eaa4fe1d3bfcda696122ba3d6b4914dba19ef96 (diff) | |
Documentation
Diffstat (limited to 'src/key.rs')
| -rw-r--r-- | src/key.rs | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -20,7 +20,7 @@ static KEY: Lazy<ThreadLocal<AtomicLock>> = 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<Self> { + pub fn get() -> Option<Self> { // 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`]. |
