Simple library for mutual exclusion based on keys. Lock and wait for execution by key.
Import the project using:
bash
cargo add key-lock
```rust use key_lock::KeyLock;
async fn main() { // Initialize new lock. let lock = KeyLock::new(); // Lock A, continues immediately. let a = lock.lock("a").await; // Lock B, continues immediately. let _b = lock.lock("b").await; // Try to lock A, but it is already locked. Normal locking would block here. assert!(lock.trylock("a").await.is_err()); } ```
This projects uses a bunch of clippy lints for higher code quality and style.
Install cargo-lints
using cargo install --git https://github.com/FlixCoder/cargo-lints
. The lints are defined in lints.toml
and can be checked by running cargo lints clippy --all-targets --workspace
.