[−][src]Struct yewtil::History
Wrapper that keeps track of prior values that have been assigned to it.
It keeps values that have been set
for it around for the duration of its lifetime,
or until they are dropped by calling reset
or forget
.
Prior values can be iterated over as well.
Methods
impl<T> History<T>
[src]
pub fn new(value: T) -> Self
[src]
Creates a new history wrapper.
pub fn set(&mut self, value: T)
[src]
Set the value represented by the History
struct.
This pushes the new value into the front of a list, where the front-most value represents the most recent value.
Example
let mut history = History::new(0); history.set(1); assert_eq!(*history, 1); assert_eq!(history.count(), 2);
pub fn replace(&mut self, value: T)
[src]
Replaces the current value without creating a history entry.
Example
let mut history = History::new(0); history.replace(1); assert_eq!(*history, 1); assert_eq!(history.count(), 1);
pub fn forget(&mut self) -> bool
[src]
Removes all prior values.
This effectively sets a new "checkpoint" that can be restored by calling reset
.
The returned bool indicates if any entries were removed.
Example
let mut history = History::new(0); history.set(1); history.set(2); history.forget(); assert_eq!(*history, 2); assert_eq!(history.count(), 1);
pub fn reset(&mut self) -> bool
[src]
Remove all elements except the last one, making the oldest entry the "current value".
The returned bool indicates if any entries were removed.
Example
let mut history = History::new(0); history.set(1); history.set(2); history.reset(); assert_eq!(*history, 0); assert_eq!(history.count(), 1);
pub fn dirty(&mut self) -> bool
[src]
Returns true if there is more than one entry in the history.
Example
let mut history = History::new(0); history.set(1); assert!(history.dirty());
pub fn count(&self) -> usize
[src]
Returns the number of entries in the history.
This will never be less than 1, as the first entry of the backing VecDeque is always occupied by the
"current value" in the History
struct.
Example
let mut history = History::new(0); assert_eq!(history.count(), 1); history.set(1); assert_eq!(history.count(), 2);
pub fn iter(&self) -> Iter<T>
[src]
Produces an iterator over references to history items ordered from newest to oldest.
pub fn into_inner(self) -> T
[src]
Gets the current value.
impl<T: PartialEq> History<T>
[src]
pub fn neq_set(&mut self, value: T) -> bool
[src]
Will only set
the value if the provided value is different than the current value.
It returns true to indicate if the history's current value was updated to be the provided value.
Example
let mut history = History::new(0); let did_set = history.neq_set(0); assert!(!did_set); let did_set = history.neq_set(1); assert!(did_set);
Trait Implementations
impl<T> AsRef<T> for History<T>
[src]
impl<T> IntoIterator for History<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> Deref for History<T>
[src]
Auto Trait Implementations
impl<T> Send for History<T> where
T: Send,
T: Send,
impl<T> Sync for History<T> where
T: Sync,
T: Sync,
impl<T> Unpin for History<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for History<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for History<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T> Any for T where
T: Any,
T: Any,