2 releases

0.1.1 Jul 4, 2023
0.1.0 Jun 30, 2023

#9 in #cloned

Download history 12/week @ 2024-02-11 135/week @ 2024-02-18 87/week @ 2024-02-25 58/week @ 2024-03-03 39/week @ 2024-03-10 19/week @ 2024-03-17 47/week @ 2024-03-24 47/week @ 2024-03-31 16/week @ 2024-04-07

80 downloads per month

MIT license

7KB
134 lines

arbitrary-lock

Acquire a lock on an arbitrary key, like a string or integer.

Usage

Add the dependency to your project:

cargo add arbitrary-lock

Use the struct:

// This can be cheaply cloned.
// The key must be Hash + Eq + Clone.
// Provide your preferred lock type as the second generic argument. It must implement Default.
let locker = ArbitraryLock::<String, tokio::sync::Mutex<()>>::new();
{
  let _l = locker.get("user:2185724".to_string()).lock().await;
  do_something_in_database().await;
};

Dependencies

~1.6–7MB
~33K SLoC