pub struct CurrentPrevious<T> { /* private fields */ }Implementations§
Source§impl<T> CurrentPrevious<T>
impl<T> CurrentPrevious<T>
Sourcepub fn new(initial: T) -> Self
pub fn new(initial: T) -> Self
Creates a new CurrentPrevious holding the initial value as its
current value. The previous value is initially None.
§Examples
let current_previous = CurrentPrevious::new(0);
assert_eq!(current_previous.current(), &0);
assert_eq!(current_previous.previous(), None);Sourcepub fn update(&mut self, new: T)
pub fn update(&mut self, new: T)
Sets a new current value, replacing the previous value with the old
current value.
§Examples
let mut current_previous = CurrentPrevious::new(0);
assert_eq!(current_previous.current(), &0);
assert_eq!(current_previous.previous(), None);
current_previous.update(1);
assert_eq!(current_previous.current(), &1);
assert_eq!(current_previous.previous(), Some(&0));Sourcepub fn reset(&mut self, new: T)
pub fn reset(&mut self, new: T)
Replaces self with a new CurrentPrevious constructed from the given
new value.
§Examples
let mut current_previous = CurrentPrevious::new(0);
assert_eq!(current_previous.current(), &0);
assert_eq!(current_previous.previous(), None);
current_previous.reset(1);
assert_eq!(current_previous.current(), &1);
assert_eq!(current_previous.previous(), None);Sourcepub fn clear_previous(&mut self)
pub fn clear_previous(&mut self)
Sets the previous value to None.
§Examples
let mut current_previous = CurrentPrevious::new(0);
assert_eq!(current_previous.current(), &0);
assert_eq!(current_previous.previous(), None);
current_previous.update(1);
assert_eq!(current_previous.current(), &1);
assert_eq!(current_previous.previous(), Some(&0));
current_previous.clear_previous();
assert_eq!(current_previous.current(), &1);
assert_eq!(current_previous.previous(), None);Trait Implementations§
Source§impl<T: Clone> Clone for CurrentPrevious<T>
impl<T: Clone> Clone for CurrentPrevious<T>
Source§fn clone(&self) -> CurrentPrevious<T>
fn clone(&self) -> CurrentPrevious<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for CurrentPrevious<T>
impl<T: Debug> Debug for CurrentPrevious<T>
impl<T: Copy> Copy for CurrentPrevious<T>
Auto Trait Implementations§
impl<T> Freeze for CurrentPrevious<T>where
T: Freeze,
impl<T> RefUnwindSafe for CurrentPrevious<T>where
T: RefUnwindSafe,
impl<T> Send for CurrentPrevious<T>where
T: Send,
impl<T> Sync for CurrentPrevious<T>where
T: Sync,
impl<T> Unpin for CurrentPrevious<T>where
T: Unpin,
impl<T> UnwindSafe for CurrentPrevious<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more