shardmap 0.3.0

Sharded embedded in-memory map with optional cache, protocol, and server internals
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use shardmap::ShardCache;

fn main() {
    let cache = ShardCache::with_capacity(128);

    cache.insert_slice(b"job:1", b"queued");
    assert_eq!(cache.get_owned(b"job:1").unwrap().as_ref(), b"queued");

    if let Some(mut value) = cache.get_mut(b"job:1") {
        value.set_slice(b"running");
    }

    assert!(cache.try_insert_slice(b"job:2", b"queued"));
    assert!(!cache.try_insert_slice(b"job:2", b"duplicate"));

    assert_eq!(cache.remove(b"job:1").unwrap().as_ref(), b"running");
    assert_eq!(cache.get_owned(b"job:2").unwrap().as_ref(), b"queued");
}