1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! A concurrent, lock-free version of `HashMap<K, Mutex<V>>` and `HashMap<K, RwLock<V>>`.
//!
//! It automatically allocates mutexes and rwlocks for you, and it automatically deallocates
//! them when they are no longer in use. The "no longer in use" condition is when the last
//! guard is dropped AND [`Empty::is_empty`] returns `true`.
//!
//! It's a bit like [Web Locks API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API)
//! when `V`` is `()`.
//!
//! # Example
//!
//! ```
//! use std::sync::Arc;
//!
//! fn main() {
//!     let locks = KeyMutex::<u32, BTreeSet<String>>::new();
//!     let mut lock = locks.lock(1).unwrap();
//!     lock.insert("Hello".to_owned());
//!     lock.insert("World".to_owned());
//!     drop(lock);
//!
//!     // Value is not empty and thus is not dropped
//!     assert_eq!(locks.len(), 1);
//!
//!     let mut lock = locks.lock(1).unwrap();
//!     assert_eq!(lock.len(), 2);
//!     lock.clear();
//!     drop(lock);
//!
//!     // Should be dropped now
//!     assert_eq!(locks.len(), 0);
//! }

mod empty;
#[macro_use]
mod inner;

pub mod std;
#[cfg(feature = "tokio")]
pub mod tokio;

pub use empty::Empty;
pub use std::*;