MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / main

Function main

code/chapter09/lru.rs:167–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

165}
166
167fn main() {
168 //let mut cache = LRUCache::new();
169 let mut cache = LRUCache::with_capacity(2);
170 cache.insert("foo", 1);
171 cache.insert("bar", 2);
172
173 cache.get(&"foo").unwrap();
174 cache.insert("baz", 3);
175
176 assert!(cache.contains(&"foo"));
177 assert!(cache.contains(&"baz"));
178 assert!(!cache.contains(&"bar"));
179
180 cache.get_mut(&"foo").unwrap();
181 cache.insert("qux", 4);
182
183 assert!(cache.contains(&"foo"));
184 assert!(cache.contains(&"qux"));
185 assert!(!cache.contains(&"baz"));
186}

Callers

nothing calls this directly

Calls 3

insertMethod · 0.45
getMethod · 0.45
get_mutMethod · 0.45

Tested by

no test coverage detected