pub struct CheckpointManager {
pub max_checkpoints: usize,
/* private fields */
}Expand description
Manages a bounded list of checkpoints.
When the checkpoint count exceeds max_checkpoints, the oldest (by
created_at) is evicted automatically.
Fields§
§max_checkpoints: usizeImplementations§
Source§impl CheckpointManager
impl CheckpointManager
Sourcepub fn create(
&mut self,
name: impl Into<String>,
pos: Vec2,
snapshot: WorldSnapshot,
) -> u64
pub fn create( &mut self, name: impl Into<String>, pos: Vec2, snapshot: WorldSnapshot, ) -> u64
Create a new checkpoint and return its id.
If the checkpoint list is at capacity, the oldest checkpoint is removed.
Sourcepub fn create_with_time(
&mut self,
name: impl Into<String>,
pos: Vec2,
snapshot: WorldSnapshot,
created_at: f64,
) -> u64
pub fn create_with_time( &mut self, name: impl Into<String>, pos: Vec2, snapshot: WorldSnapshot, created_at: f64, ) -> u64
Like create but with an explicit game-time timestamp.
Sourcepub fn get(&self, id: u64) -> Option<&Checkpoint>
pub fn get(&self, id: u64) -> Option<&Checkpoint>
Get a checkpoint by id.
Sourcepub fn get_mut(&mut self, id: u64) -> Option<&mut Checkpoint>
pub fn get_mut(&mut self, id: u64) -> Option<&mut Checkpoint>
Get a mutable checkpoint by id.
Sourcepub fn get_nearest(&self, pos: Vec2) -> Option<&Checkpoint>
pub fn get_nearest(&self, pos: Vec2) -> Option<&Checkpoint>
Get the checkpoint closest to pos (Euclidean distance).
Sourcepub fn get_most_recent(&self) -> Option<&Checkpoint>
pub fn get_most_recent(&self) -> Option<&Checkpoint>
Get the most recently created checkpoint (highest created_at).
Sourcepub fn get_within_radius(&self, pos: Vec2, radius: f32) -> Vec<&Checkpoint>
pub fn get_within_radius(&self, pos: Vec2, radius: f32) -> Vec<&Checkpoint>
Get all checkpoints within radius of pos, sorted by distance.
Sourcepub fn list(&self) -> &[Checkpoint]
pub fn list(&self) -> &[Checkpoint]
Iterate over all checkpoints.
Sourcepub fn remove(&mut self, id: u64) -> bool
pub fn remove(&mut self, id: u64) -> bool
Remove the checkpoint with the given id. Returns true if found.
pub fn is_empty(&self) -> bool
pub fn is_at_cap(&self) -> bool
Sourcepub fn serialize_all(&self) -> Vec<u8> ⓘ
pub fn serialize_all(&self) -> Vec<u8> ⓘ
Serialize all checkpoints to a JSON byte vector.
Sourcepub fn deserialize_all(
bytes: &[u8],
) -> Result<Vec<Checkpoint>, DeserializeError>
pub fn deserialize_all( bytes: &[u8], ) -> Result<Vec<Checkpoint>, DeserializeError>
Deserialize checkpoints from a JSON byte vector (as produced by serialize_all).
Sourcepub fn load_from_bytes(&mut self, bytes: &[u8]) -> Result<(), DeserializeError>
pub fn load_from_bytes(&mut self, bytes: &[u8]) -> Result<(), DeserializeError>
Restore checkpoints from bytes, replacing any existing ones.
Auto Trait Implementations§
impl Freeze for CheckpointManager
impl RefUnwindSafe for CheckpointManager
impl Send for CheckpointManager
impl Sync for CheckpointManager
impl Unpin for CheckpointManager
impl UnsafeUnpin for CheckpointManager
impl UnwindSafe for CheckpointManager
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
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.