[][src]Struct yewtil::History

pub struct History<T>(_);

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.

Implementations

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> Deref for History<T>[src]

type Target = T

The resulting type after dereferencing.

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?

Auto Trait Implementations

impl<T> RefUnwindSafe for History<T> where
    T: RefUnwindSafe

impl<T> Send for History<T> where
    T: Send

impl<T> Sync for History<T> where
    T: Sync

impl<T> Unpin for History<T> where
    T: Unpin

impl<T> UnwindSafe for History<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

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?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.