From 43854d39e866cadc4f2557f67be864dec5345a4a Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sun, 7 Apr 2024 20:11:50 -0700 Subject: [PATCH] Derive Debug and Clone --- src/lib.rs | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1984915..0c45c6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,10 +10,10 @@ //! [`LRUCache`] uses a fixed-capacity array for storage. It provides `O(1)` insertion, and `O(n)` //! lookup. It does not require an allocator and can be used in `no_std` crates. //! -//! See the [`LRUCache`](LRUCache) docs for details. +//! See the [`LRUCache`] docs for details. use arrayvec::ArrayVec; -use core::{fmt, mem::replace}; +use core::mem::replace; #[cfg(test)] mod tests; @@ -55,6 +55,7 @@ mod tests; /// cache.insert(MyValue { id: 4, name: "Mars" }); /// assert!(cache.find(|x| x.id == 2).is_none()); /// ``` +#[derive(Debug, Clone)] pub struct LRUCache { /// The most-recently-used entry is at index `head`. The entries form a linked list, linked to /// each other by indices within the `entries` array. After an entry is added to the array, @@ -270,32 +271,6 @@ impl LRUCache { } } -impl Clone for LRUCache -where - T: Clone, -{ - fn clone(&self) -> Self { - Self { - entries: self.entries.clone(), - head: self.head, - tail: self.tail, - } - } -} - -impl fmt::Debug for LRUCache -where - T: fmt::Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LRUCache") - .field("head", &self.head) - .field("tail", &self.tail) - .field("entries", &self.entries) - .finish() - } -} - /// Mutable iterator over values in an `LRUCache`, from most-recently-used to least-recently-used. struct IterMut<'a, T, const N: usize> { cache: &'a mut LRUCache,