diff --git a/src/lib.rs b/src/lib.rs index c457e62..5d5ad8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,20 +78,25 @@ struct Entry { impl Default for LRUCache { fn default() -> Self { + Self::new() + } +} + +impl LRUCache { + /// Create an empty cache. + pub const fn new() -> Self { let cache = LRUCache { - entries: ArrayVec::new(), + entries: ArrayVec::new_const(), head: 0, tail: 0, }; assert!( - cache.entries.capacity() < u16::max_value() as usize, + N < u16::max_value() as usize, "Capacity overflow" ); cache } -} -impl LRUCache { /// Insert a given key in the cache. /// /// This item becomes the front (most-recently-used) item in the cache. If the cache is full, diff --git a/src/tests.rs b/src/tests.rs index 978e129..2db361d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -20,7 +20,7 @@ where #[test] fn empty() { - let mut cache = TestCache::default(); + let mut cache = TestCache::new(); assert_eq!(cache.is_empty(), true); assert_eq!(items(&mut cache), []); cache.insert(1);