pub struct SaveManager {
pub save_dir: String,
/* private fields */
}Expand description
Manages multiple save slots under a single directory.
Slots are numbered from 0. Slot 255 is reserved for the auto-save.
Fields§
§save_dir: StringDirectory where save files are stored.
Implementations§
Source§impl SaveManager
impl SaveManager
Sourcepub fn new(save_dir: impl Into<String>) -> Self
pub fn new(save_dir: impl Into<String>) -> Self
Create a new SaveManager pointing at save_dir.
The directory is created lazily when a save is written.
Sourcepub fn list_slots(&self, max: usize) -> Vec<SaveSlot>
pub fn list_slots(&self, max: usize) -> Vec<SaveSlot>
Return up to max slot descriptors (0 through max-1), reading headers
from disk where save files exist.
Sourcepub fn save_to_slot(
&self,
slot: u8,
snapshot: WorldSnapshot,
header: SaveHeader,
) -> Result<(), SaveError>
pub fn save_to_slot( &self, slot: u8, snapshot: WorldSnapshot, header: SaveHeader, ) -> Result<(), SaveError>
Write a save to slot slot.
Sourcepub fn load_slot(&self, slot: u8) -> Result<SaveFile, SaveError>
pub fn load_slot(&self, slot: u8) -> Result<SaveFile, SaveError>
Load the full save file from slot slot.
Sourcepub fn delete_slot(&self, slot: u8) -> Result<(), SaveError>
pub fn delete_slot(&self, slot: u8) -> Result<(), SaveError>
Delete the save file in slot slot.
Sourcepub fn auto_save(&self, snapshot: WorldSnapshot) -> Result<(), SaveError>
pub fn auto_save(&self, snapshot: WorldSnapshot) -> Result<(), SaveError>
Write the auto-save slot.
Sourcepub fn has_auto_save(&self) -> bool
pub fn has_auto_save(&self) -> bool
Returns true if an auto-save file exists.
Sourcepub fn load_auto_save(&self) -> Result<SaveFile, SaveError>
pub fn load_auto_save(&self) -> Result<SaveFile, SaveError>
Load the auto-save.
Sourcepub fn most_recent_slot(&self) -> Option<u8>
pub fn most_recent_slot(&self) -> Option<u8>
Return the slot number of the most recently written save (by Unix timestamp).
Scans up to the first 32 slots plus the auto-save slot.
Sourcepub fn ensure_dir(&self) -> Result<(), SaveError>
pub fn ensure_dir(&self) -> Result<(), SaveError>
Ensure the save directory exists.
Sourcepub fn used_slot_count(&self) -> usize
pub fn used_slot_count(&self) -> usize
Count non-empty slots (0..32).
Auto Trait Implementations§
impl Freeze for SaveManager
impl RefUnwindSafe for SaveManager
impl Send for SaveManager
impl Sync for SaveManager
impl Unpin for SaveManager
impl UnsafeUnpin for SaveManager
impl UnwindSafe for SaveManager
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.