|
37 | 37 | //! assert!(cache.get_mut(&2).is_none()); |
38 | 38 | //! ``` |
39 | 39 | //! |
40 | | -//! The cache can also be limited by an arbitrary metric calculated from its key-value pairs, see |
41 | | -//! [`LruCache::with_meter`][with_meter] for more information. If the `heapsize` feature is enabled, |
42 | | -//! this crate provides one such alternate metric—`HeapSize`. Custom metrics can be written by |
43 | | -//! implementing the [`Meter`][meter] trait. |
44 | | -//! |
45 | | -//! [with_meter]: struct.LruCache.html#method.with_meter |
46 | | -//! [meter]: trait.Meter.html |
47 | | -
|
48 | | -#[cfg(feature = "heapsize")] |
49 | | -extern crate heapsize; |
50 | | - |
51 | 40 | use std::borrow::Borrow; |
52 | 41 | use std::collections::hash_map::RandomState; |
53 | 42 | use std::fmt; |
@@ -153,33 +142,6 @@ impl<K, V> CountableMeterWithMeasure<K, V, ()> for Count { |
153 | 142 | } |
154 | 143 | } |
155 | 144 |
|
156 | | -#[cfg(feature = "heapsize")] |
157 | | -mod heap_meter { |
158 | | - use heapsize::HeapSizeOf; |
159 | | - use std::borrow::Borrow; |
160 | | - |
161 | | - /// Size limit based on the heap size of each cache item. |
162 | | - /// |
163 | | - /// Requires cache entries that implement [`HeapSizeOf`][1]. |
164 | | - /// |
165 | | - /// [1]: https://doc.servo.org/heapsize/trait.HeapSizeOf.html |
166 | | - pub struct HeapSize; |
167 | | - |
168 | | - impl<K, V: HeapSizeOf> super::Meter<K, V> for HeapSize { |
169 | | - type Measure = usize; |
170 | | - |
171 | | - fn measure<Q: ?Sized>(&self, _: &Q, item: &V) -> usize |
172 | | - where |
173 | | - K: Borrow<Q>, |
174 | | - { |
175 | | - item.heap_size_of_children() + ::std::mem::size_of::<V>() |
176 | | - } |
177 | | - } |
178 | | -} |
179 | | - |
180 | | -#[cfg(feature = "heapsize")] |
181 | | -pub use heap_meter::*; |
182 | | - |
183 | 145 | /// An LRU cache. |
184 | 146 | #[derive(Clone)] |
185 | 147 | pub struct LruCache<K: Eq + Hash, V, S: BuildHasher = RandomState, M: CountableMeter<K, V> = Count> |
@@ -906,19 +868,4 @@ mod tests { |
906 | 868 | assert!(!cache.contains_key("foo1")); |
907 | 869 | assert!(!cache.contains_key("foo2")); |
908 | 870 | } |
909 | | - |
910 | | - #[cfg(feature = "heapsize")] |
911 | | - #[test] |
912 | | - fn test_heapsize_cache() { |
913 | | - use super::HeapSize; |
914 | | - |
915 | | - let mut cache = LruCache::<&str, (u8, u8, u8), _, _>::with_meter(8, HeapSize); |
916 | | - cache.insert("foo1", (1, 2, 3)); |
917 | | - cache.insert("foo2", (4, 5, 6)); |
918 | | - cache.insert("foo3", (7, 8, 9)); |
919 | | - assert!(!cache.contains_key("foo1")); |
920 | | - cache.insert("foo2", (10, 11, 12)); |
921 | | - cache.insert("foo4", (13, 14, 15)); |
922 | | - assert!(!cache.contains_key("foo3")); |
923 | | - } |
924 | 871 | } |
0 commit comments