Struct smoltcp::storage::RingBuffer [] [src]

pub struct RingBuffer<'a, T: 'a> { /* fields omitted */ }

A ring buffer.

This ring buffer implementation provides many ways to interact with it:

  • Enqueueing or dequeueing one element from corresponding side of the buffer;
  • Enqueueing or dequeueing a slice of elements from corresponding side of the buffer;
  • Accessing allocated and unallocated areas directly.

It is also zero-copy; all methods provide references into the buffer's storage. Note that all references are mutable; it is considered more important to allow in-place processing than to protect from accidental mutation.

This implementation is suitable for both simple uses such as a FIFO queue of UDP packets, and advanced ones such as a TCP reassembly buffer.

Methods

impl<'a, T: 'a> RingBuffer<'a, T>
[src]

[src]

Create a ring buffer with the given storage.

During creation, every element in storage is reset.

[src]

Clear the ring buffer.

[src]

Return the maximum number of elements in the ring buffer.

[src]

Clear the ring buffer, and reset every element.

[src]

Return the current number of elements in the ring buffer.

[src]

Return the number of elements that can be added to the ring buffer.

[src]

Query whether the buffer is empty.

[src]

Query whether the buffer is full.

impl<'a, T: 'a> RingBuffer<'a, T>
[src]

This is the "discrete" ring buffer interface: it operates with single elements, and boundary conditions (empty/full) are errors.

[src]

Call f with a single buffer element, and enqueue the element if f returns successfully, or return Err(Error::Exhausted) if the buffer is full.

[src]

Enqueue a single element into the buffer, and return a reference to it, or return Err(Error::Exhausted) if the buffer is full.

This function is a shortcut for ring_buf.enqueue_one_with(Ok).

[src]

Call f with a single buffer element, and dequeue the element if f returns successfully, or return Err(Error::Exhausted) if the buffer is empty.

[src]

Dequeue an element from the buffer, and return a reference to it, or return Err(Error::Exhausted) if the buffer is empty.

This function is a shortcut for ring_buf.dequeue_one_with(Ok).

impl<'a, T: 'a> RingBuffer<'a, T>
[src]

This is the "continuous" ring buffer interface: it operates with element slices, and boundary conditions (empty/full) simply result in empty slices.

[src]

Call f with the largest contiguous slice of unallocated buffer elements, and enqueue the amount of elements returned by f.

Panics

This function panics if the amount of elements returned by f is larger than the size of the slice passed into it.

[src]

Enqueue a slice of elements up to the given size into the buffer, and return a reference to them.

This function may return a slice smaller than the given size if the free space in the buffer is not contiguous.

[src]

Enqueue as many elements from the given slice into the buffer as possible, and return the amount of elements that could fit.

[src]

Call f with the largest contiguous slice of allocated buffer elements, and dequeue the amount of elements returned by f.

Panics

This function panics if the amount of elements returned by f is larger than the size of the slice passed into it.

[src]

Dequeue a slice of elements up to the given size from the buffer, and return a reference to them.

This function may return a slice smaller than the given size if the allocated space in the buffer is not contiguous.

[src]

Dequeue as many elements from the buffer into the given slice as possible, and return the amount of elements that could fit.

impl<'a, T: 'a> RingBuffer<'a, T>
[src]

This is the "random access" ring buffer interface: it operates with element slices, and allows to access elements of the buffer that are not adjacent to its head or tail.

[src]

Return the largest contiguous slice of unallocated buffer elements starting at the given offset past the last allocated element, and up to the given size.

[src]

Write as many elements from the given slice into unallocated buffer elements starting at the given offset past the last allocated element, and return the amount written.

[src]

Enqueue the given number of unallocated buffer elements.

Panics

Panics if the number of elements given exceeds the number of unallocated elements.

[src]

Return the largest contiguous slice of allocated buffer elements starting at the given offset past the first allocated element, and up to the given size.

[src]

Read as many elements from allocated buffer elements into the given slice starting at the given offset past the first allocated element, and return the amount read.

[src]

Dequeue the given number of allocated buffer elements.

Panics

Panics if the number of elements given exceeds the number of allocated elements.

Trait Implementations

impl<'a, T: Debug + 'a> Debug for RingBuffer<'a, T>
[src]

[src]

Formats the value using the given formatter.

impl<'a, T: 'a> From<ManagedSlice<'a, T>> for RingBuffer<'a, T>
[src]

[src]

Performs the conversion.