pub struct GenerationalBuffer<T> { /* private fields */ }
Expand description
A generic append-only circular buffer with generational IDs
Inserting returns a Handle
that can be used to access the value later,
checking the item hasn’t been replaced in the meantime.
Items can’t be individually removed, but the entire buffer can be cleared, which invalidates all existing handles.
Implementations§
Source§impl<T> GenerationalBuffer<T>
impl<T> GenerationalBuffer<T>
Sourcepub fn new(max_capacity: usize) -> Self
pub fn new(max_capacity: usize) -> Self
Creates a new generational buffer with the specified capacity
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the buffer, removing all entries and rendering all existing handles invalid.
Sourcepub fn push(&mut self, value: T) -> Handle<T>
pub fn push(&mut self, value: T) -> Handle<T>
Inserts a value into the buffer and returns a handle to it.
This removes the oldest entry if the buffer is full.
Sourcepub fn get(&self, handle: Handle<T>) -> Option<&T>
pub fn get(&self, handle: Handle<T>) -> Option<&T>
Gets a reference to the value associated with the handle
Sourcepub fn get_mut(&mut self, handle: Handle<T>) -> Option<&mut T>
pub fn get_mut(&mut self, handle: Handle<T>) -> Option<&mut T>
Gets a mutable reference to the value associated with the handle
Sourcepub fn is_valid(&self, handle: Handle<T>) -> bool
pub fn is_valid(&self, handle: Handle<T>) -> bool
Checks if a handle is still valid (points to existing data)
Sourcepub fn iter(&self) -> impl Iterator<Item = (Handle<T>, &T)>
pub fn iter(&self) -> impl Iterator<Item = (Handle<T>, &T)>
Returns an iterator over all entries with their handles, in no particular order