Struct rbuf::RingBuf[][src]

pub struct RingBuf<T> { /* fields omitted */ }
Expand description

A ring buffer for arbitrary but default-initializable data.

The ring buffer is always “full”, but may only contain “default” representations of the given type if nothing else has been inserted. There is no concept of a removing elements, only overwriting them with the default. Gaps or non-existent elements can be represented by having an element type Option<T>.

One implication of the above is that iteration will always yield as many elements as the ring buffer’s size.

Indexing into the ring buffer using bracket notation works in such a way that an index of 0 always accesses the least recently added element and an index of self.len() - 1 the most recently added one. Furthermore, indexes wrap around at the ring buffer’s end, meaning that an index of value self.len() would access the same element as index 0.

Implementations

Create a new RingBuf of a fixed length as provided.

len must be greater than zero.

Pop the most recently added element from the ring buffer.

This operation will remove the ring buffer’s most recently added element and replace it with the default value of T. The formerly second most recently added element will be the ring buffer’s new “front”.

Convert the RingBuf into a boxed slice of its contents.

Create a new RingBuf with data from a Vec.

Note that the vector’s first element is considered the oldest one, which means that the first read will access it and pushed data will overwrite it first. Note furthermore that the provided Vec is required to contain at least a single element.

Retrieve the ring buffer’s length.

Retrieve the current “front” element, i.e., the element that got inserted most recently.

Retrieve the current “front” element, i.e., the element that got inserted most recently.

Retrieve the current “front” index, i.e., the index of the element that got inserted most recently.

Note that this index only has real relevance when accessing the underlying slice using deref. In particular, the index returned by this method should not be confused with those as expected by our Index implementation (as accessible through bracket syntax).

Retrieve the current “back” element, i.e., the element that got inserted the furthest in the past.

Retrieve the current “back” element, i.e., the element that got inserted the furthest in the past.

Retrieve the current “back” index, i.e., the index of the element that got inserted the furthest in the past.

Note that this index only has real relevance when accessing the underlying slice using deref. In particular, the index returned by this method should not be confused with those as expected by our Index implementation (as accessible through bracket syntax).

Push an element into the ring buffer.

This operation will evict the ring buffer’s least recently added element (i.e., the element at the back) and replace it with the provided one. The newly pushed element will be considered the ring buffer’s new “front”.

Retrieve an iterator over the elements of the ring buffer.

Retrieve a mutating iterator over the elements of the ring buffer.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.