Merge pull request #2575 from m4rch3n1ng/rm-clone-trait-bound
remove unnecessary Clone trait bound for Cache::clear
This commit is contained in:
commit
62b4da87d1
1 changed files with 10 additions and 9 deletions
|
|
@ -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 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue