Skip to main content

RingBufferTrait

Trait RingBufferTrait 

Source
pub trait RingBufferTrait {
    type Value;
    type Container: IntoIterator;
    type Iter<'a>: Iterator<Item = &'a Step<Self::Value>>
       where Self: 'a;
    type IterMut<'a>: Iterator<Item = &'a mut Step<Self::Value>>
       where Self: 'a;

    // Required methods
    fn new() -> Self;
    fn is_empty(&self) -> bool;
    fn len(&self) -> usize;
    fn get_back(&self) -> Option<&Step<Self::Value>>;
    fn get_front(&self) -> Option<&Step<Self::Value>>;
    fn pop_front(&mut self) -> Option<Step<Self::Value>>;
    fn pop_back(&mut self) -> Option<Step<Self::Value>>;
    fn add_step(&mut self, step: Step<Self::Value>);
    fn update_step(&mut self, step: Step<Self::Value>) -> bool;
    fn prune(&mut self, max_age: Duration);
    fn iter<'a>(&'a self) -> Self::Iter<'a>;
}
Expand description

Common interface for timestamped ring buffers.

Implementors are expected to maintain steps in ascending timestamp order.

Required Associated Types§

Source

type Value

The value type stored in each Step.

Source

type Container: IntoIterator

The backing container type that stores steps.

Source

type Iter<'a>: Iterator<Item = &'a Step<Self::Value>> where Self: 'a

Immutable iterator over stored steps.

Source

type IterMut<'a>: Iterator<Item = &'a mut Step<Self::Value>> where Self: 'a

Mutable iterator over stored steps.

Required Methods§

Source

fn new() -> Self

Creates an empty buffer.

Source

fn is_empty(&self) -> bool

Returns true when the buffer contains no steps.

Source

fn len(&self) -> usize

Returns the number of stored steps.

Source

fn get_back(&self) -> Option<&Step<Self::Value>>

Returns the newest step, if any.

Source

fn get_front(&self) -> Option<&Step<Self::Value>>

Returns the oldest step, if any.

Source

fn pop_front(&mut self) -> Option<Step<Self::Value>>

Removes and returns the oldest step.

Source

fn pop_back(&mut self) -> Option<Step<Self::Value>>

Removes and returns the newest step.

Source

fn add_step(&mut self, step: Step<Self::Value>)

Appends a step to the buffer.

Source

fn update_step(&mut self, step: Step<Self::Value>) -> bool

Replaces a step with matching timestamp.

Returns true if a step was updated, false if no matching timestamp was found.

Source

fn prune(&mut self, max_age: Duration)

Prune steps older than max_age from the buffer.

Source

fn iter<'a>(&'a self) -> Self::Iter<'a>

Returns an iterator over all steps from oldest to newest.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> RingBufferTrait for RingBuffer<T>
where T: Copy,

Source§

type Value = T

Source§

type Container = VecDeque<Step<T>>

Source§

type Iter<'a> = Iter<'a, Step<T>> where Self: 'a

Source§

type IterMut<'a> = IterMut<'a, Step<T>> where Self: 'a