Merge pull request #2575 from m4rch3n1ng/rm-clone-trait-bound

remove unnecessary Clone trait bound for Cache::clear
This commit is contained in:
Héctor Ramón 2024-09-13 02:02:49 +02:00 committed by GitHub
commit 62b4da87d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
//! Cache computations and efficiently reuse them. //! Cache computations and efficiently reuse them.
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::mem;
use std::sync::atomic::{self, AtomicU64}; use std::sync::atomic::{self, AtomicU64};
/// A simple cache that stores generated values to avoid recomputation. /// A simple cache that stores generated values to avoid recomputation.
@ -58,18 +59,18 @@ impl<T> Cache<T> {
} }
/// Clears the [`Cache`]. /// Clears the [`Cache`].
pub fn clear(&self) pub fn clear(&self) {
where let mut state = self.state.borrow_mut();
T: Clone,
{
use std::ops::Deref;
let previous = match self.state.borrow().deref() { let previous =
State::Empty { previous } => previous.clone(), mem::replace(&mut *state, State::Empty { previous: None });
State::Filled { current } => Some(current.clone()),
let previous = match previous {
State::Empty { previous } => previous,
State::Filled { current } => Some(current),
}; };
*self.state.borrow_mut() = State::Empty { previous }; *state = State::Empty { previous };
} }
} }