| Crates.io | chiralmap |
| lib.rs | chiralmap |
| version | 0.1.2 |
| created_at | 2025-07-20 22:37:50.038033+00 |
| updated_at | 2025-07-22 14:48:46.551083+00 |
| description | Left-Right map using IndexMap |
| homepage | https://codeberg.org/raffaeleragni/chiralmap |
| repository | https://codeberg.org/raffaeleragni/chiralmap |
| max_upload_size | |
| id | 1761487 |
| size | 63,760 |
chiralmap An IndexMap with Left-Right synchronization.
This creates 2 maps internally that are swapped at every flush. The flush is required because the map is eventually consistent and the readers will only see the new items once the maps are swapped. See left_right.
Write operations are funneled into a channel that is processed by a single thread. Creating a ChiralMap will automatically spawn this thread internally. The thread will be terminated when the last copy of ChiralMap is dropped.
The advantage of this data structure is to have access to read handles that are lock-free, as the map that is currently in read mode is basically immutable.
How to use with handles:
use chiralmap::ChiralMap;
let map = ChiralMap::<String, String>::default();
map.insert("A".into(), "B".into()).unwrap();
map.flush();
let h = map.read_handle();
let v = h.get(&"A".to_string()).unwrap();
println!("{v}"); // "B"
In case the map is shared across a web framework (requires being Sync),
then internally it uses a read pool which can be acquired through locking.
The api makes this transparent with the get() method.
use chiralmap::ChiralMap;
let map = ChiralMap::<String, String>::default();
map.insert("A".into(), "B".into()).unwrap();
map.flush();
let v = map.get(&"A".to_string()).unwrap();
println!("{v}"); // "B"