Crate providing a 100% safe, generational arena based LRU cache implementation.
```rust use generational_lru::lrucache::{LRUCache, CacheError};
let capacity = 5;
let mut lrucache = LRUCache::
for ele in 0..capacity { let x = ele as i32; assert!(lrucache.insert(x, x).isok()); }
for ele in 0..capacity { let x = ele as i32; asserteq!(lrucache.get(&x), Ok(&x)); }
let x = capacity as i32; assert!(lrucache.insert(x, x).isok());
asserteq!(lrucache.get(&x), Ok(&x));
asserteq!(lrucache.get(&0), Err(CacheError::CacheMiss));
let x = capacity as i32 / 2; asserteq!(lrucache.remove(&x), Ok(x));
asserteq!(lrucache.get(&x), Err(CacheError::CacheMiss)); asserteq!(lrucache.remove(&x), Err(CacheError::CacheMiss));
// zero capacity LRUCache is unusable
let mut lrucache = LRUCache::
assert!(matches!( lrucache.insert(0, 0), Err(CacheError::CacheBroken()) ));
```
Refer to API documentation for more details.
This is a library crate. You may include it in your Cargo.toml
as follows:
toml
[dependencies]
generational-lru = "0.1.0"
This repository is licensed under the MIT License. See LICENSE for the full license text.