Trait bufferring::storage::Storage
source · 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:
Pinsafety:get(),get_mut(), andget_pin()return the same slice (i.e. the same pointer address) for the sameselfaddress.get(),get_mut(), andget_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.