pub unsafe trait Storage {
    type Item;

    // Required methods
    fn get(&self) -> &[Slot<Self::Item>];
    fn get_mut(&mut self) -> &mut [Slot<Self::Item>];
    fn get_pin(self: Pin<&mut Self>) -> Pin<&mut [Slot<Self::Item>]>;

    // Provided method
    fn cap(&self) -> usize { ... }
}
Expand description

Storage for a ring buffer.

The storage should represent a slice of items, some of which may not be initialized. It is the responsibility of the ring buffer using the storage to track which items are initialized and also to drop them appropriately.

This is an unsafe trait: every implementation of it must satisfy certain invariants, else risk undefined behaviour:

  • Pin safety: get(), get_mut(), and get_pin() return the same slice (i.e. the same pointer address) for the same self address.
  • get(), get_mut(), and get_pin() always return a slice with the same length; the length cannot change for the duration of the object.
  • The length of the stored slice is non-zero.
  • The referenced slice’s contents must not change externally; they are only mutated by the containing ring buffer. Interior mutation is not allowed.
    • The ring buffer is free to assume that modifications it makes to the slice will persist until they are overriden by newer modifications.

Required Associated Types§

source

type Item

The type of the items stored by the buffer.

Required Methods§

source

fn get(&self) -> &[Slot<Self::Item>]

Get a shared reference to the data.

source

fn get_mut(&mut self) -> &mut [Slot<Self::Item>]

Get a unique reference to the data.

source

fn get_pin(self: Pin<&mut Self>) -> Pin<&mut [Slot<Self::Item>]>

Get a pinned reference to the data.

Provided Methods§

source

fn cap(&self) -> usize

The capacity of this storage.

Implementors§

source§

impl<T> Storage for HeapStorage<T>

§

type Item = T

source§

impl<T, const N: usize> Storage for ArrayStorage<T, N>

§

type Item = T