TimedList

Struct TimedList 

Source
pub struct TimedList<T> { /* private fields */ }
Expand description

An iterable list structure where each element has an associated Duration.

When an element’s Duration has elapsed, the element is removed from the list upon the next mutable function call. Timed-out elements will never be iterated over.

Implementations§

Source§

impl<T> TimedList<T>

Source

pub fn new() -> TimedList<T>

Creates a new TimedList

Source

pub fn insert<D: ToDuration>(&mut self, element: T, time: D)

Inserts an element into the list with the given number of floating-point seconds

Source

pub fn clean(&mut self)

Forces the removal of all elements whose Duration has elpased. This method does not need to be called manually unless you want to explicitely free the memory of timed-out elements immediately.

Source

pub fn clear(&mut self)

Removes all elements from the list

Source

pub fn len(&self) -> usize

Gets the number of elements in the list that have not timed out.

Source

pub fn is_empty(&self) -> bool

Check if the list is empty or if all existing elements have timed out.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains elements in the list that match the predicate

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>

Iterates immutably through all elements.

While this method does not remove timed-out elements, it does filter them out. If iteration takes sufficiently long, elements that may have been valid when iteration began may be skipped when they are actually iterated over.

Source

pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>

Iterates mutably through all elements.

If iteration takes sufficiently long, elements that may have been valid when iteration began may be skipped when they are actually iterated over.

Source

pub fn timer_iter(&self) -> impl DoubleEndedIterator<Item = (&T, Timer)>

Iterates immutably through all elements and their timers.

While this method does not remove timed-out elements, it does filter them out. If iteration takes sufficiently long, elements that may have been valid when iteration began may be skipped when they are actually iterated over.

Source

pub fn timer_iter_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (&mut T, Timer)>

Iterates mutably through all elements.

If iteration takes sufficiently long, elements that may have been valid when iteration began may be skipped when they are actually iterated over.

Trait Implementations§

Source§

impl<T: Clone> Clone for TimedList<T>

Source§

fn clone(&self) -> TimedList<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TimedList<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for TimedList<T>

Source§

fn default() -> TimedList<T>

Returns the “default value” for a type. Read more
Source§

impl<T, D> FromIterator<(T, D)> for TimedList<T>
where D: ToDuration,

Source§

fn from_iter<I: IntoIterator<Item = (T, D)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> IntoIterator for TimedList<T>
where T: 'static,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn DoubleEndedIterator<Item = T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for TimedList<T>

Source§

fn eq(&self, other: &TimedList<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for TimedList<T>

Source§

fn partial_cmp(&self, other: &TimedList<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> StructuralPartialEq for TimedList<T>

Auto Trait Implementations§

§

impl<T> Freeze for TimedList<T>

§

impl<T> RefUnwindSafe for TimedList<T>
where T: RefUnwindSafe,

§

impl<T> Send for TimedList<T>
where T: Send,

§

impl<T> Sync for TimedList<T>
where T: Sync,

§

impl<T> Unpin for TimedList<T>
where T: Unpin,

§

impl<T> UnwindSafe for TimedList<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.