MCPcopy Index your code
hub / github.com/TennyZhuang/ref-stable-lru

github.com/TennyZhuang/ref-stable-lru @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
33 symbols 87 edges 9 files 3 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

LRU Cache with compile-time reference stability

The main codes are copy from lru-rs, very grateful for the project.

The main motivation for implementing this project is that LRUCache should allow multiple immutable references obtained through get method. Currently, this crate is under the active development stage. The purpose of this crate is to validate the new design pattern and hope to apply it to more collection libraries, preferably including std. As for this library itself, I would prefer its proposed new API to be merged to upstream.

The main idea is separating the value operating permissions from the data structure itself. The blog post elaborates the idea. You can also take a look at uitest, which explains the API design goals.

Example

Below is a simple example shows the main feature of LRUCache.

let mut cache = LruCache::new(NonZeroUsize::new(2).unwrap());

cache.scope(|mut cache, mut perm| {
    assert_eq!(cache.put("apple", "red", &mut perm), None);
    assert_eq!(cache.put("banana", "yellow", &mut perm), None);
    assert_eq!(cache.put("lemon", "yellow", &mut perm), Some("red"));

    let colors: Vec<_> = ["apple", "banana", "lemon", "watermelon"]
        .iter()
        .map(|k| cache.get(k, &perm))
        .collect();
    assert!(colors[0].is_none());
    assert_opt_eq(colors[1], "yellow");
    assert_opt_eq(colors[2], "yellow");
    assert!(colors[3].is_none());
});

Core symbols most depended-on inside this repo

get
called by 26
src/lib.rs
put
called by 18
src/lib.rs
scope
called by 15
src/lib.rs
peek_mut
called by 7
src/lib.rs
assert_opt_eq_mut
called by 5
src/lib.rs
assert_opt_eq
called by 4
src/lib.rs
detach
called by 3
src/lib.rs
attach
called by 3
src/lib.rs

Shape

Method 15
Function 13
Class 5

Languages

Rust100%

Modules by API surface

src/lib.rs25 symbols
tests/ui/test.rs1 symbols
tests/ui/put-while-holding-ref.rs1 symbols
tests/ui/len-while-holding-mut.rs1 symbols
tests/ui/handle-with-wrong-perm.rs1 symbols
tests/ui/drop-handle-while-holding-ref.rs1 symbols
tests/ui/double-get-without-scope.rs1 symbols
tests/ui/double-get-in-scope.rs1 symbols
tests/ui/concurrent-use-refs.rs1 symbols

For agents

$ claude mcp add ref-stable-lru \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact