pub struct SnapshotRingBuffer { /* private fields */ }Expand description
Ring buffer for storing recent world snapshots. Supports efficient lookup by snapshot ID and tick number.
Implementations§
Source§impl SnapshotRingBuffer
impl SnapshotRingBuffer
pub fn new(capacity: usize) -> Self
pub fn push(&mut self, snapshot: WorldSnapshot)
pub fn get(&self, id: SnapshotId) -> Option<&WorldSnapshot>
pub fn get_by_tick(&self, tick: u64) -> Option<&WorldSnapshot>
pub fn latest(&self) -> Option<&WorldSnapshot>
pub fn latest_id(&self) -> SnapshotId
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
pub fn is_full(&self) -> bool
Sourcepub fn recent(&self, n: usize) -> Vec<&WorldSnapshot>
pub fn recent(&self, n: usize) -> Vec<&WorldSnapshot>
Get the N most recent snapshots, ordered oldest to newest.
Sourcepub fn closest_to_tick(&self, tick: u64) -> Option<&WorldSnapshot>
pub fn closest_to_tick(&self, tick: u64) -> Option<&WorldSnapshot>
Find the closest snapshot to a given tick.
Sourcepub fn compute_delta(
&self,
baseline_id: SnapshotId,
target_id: SnapshotId,
) -> Option<SnapshotDelta>
pub fn compute_delta( &self, baseline_id: SnapshotId, target_id: SnapshotId, ) -> Option<SnapshotDelta>
Compute delta between two stored snapshots.
Sourcepub fn prune_before(&mut self, tick: u64)
pub fn prune_before(&mut self, tick: u64)
Remove all snapshots older than the given tick.
pub fn clear(&mut self)
Sourcepub fn stored_ids(&self) -> Vec<SnapshotId>
pub fn stored_ids(&self) -> Vec<SnapshotId>
Collect all snapshot IDs currently stored, in no particular order.
Auto Trait Implementations§
impl Freeze for SnapshotRingBuffer
impl RefUnwindSafe for SnapshotRingBuffer
impl Send for SnapshotRingBuffer
impl Sync for SnapshotRingBuffer
impl Unpin for SnapshotRingBuffer
impl UnsafeUnpin for SnapshotRingBuffer
impl UnwindSafe for SnapshotRingBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.