Skip to main content

SaveManager

Struct SaveManager 

Source
pub struct SaveManager<S: SaveData> { /* private fields */ }
Expand description

Manages save/load operations across multiple slots.

S is the game-specific type implementing SaveData.

Implementations§

Source§

impl<S: SaveData> SaveManager<S>

Source

pub fn new(storage: Box<dyn SaveStorage>) -> Self

Create a new save manager backed by the given storage implementation.

Examples found in repository?
examples/hello_dotzuki.rs (line 565)
562fn demo_save_load() {
563    println!("\n╔══ SAVE / LOAD ═════════════════════════╗");
564    let storage = Box::new(InMemoryStorage::new());
565    let manager = SaveManager::<GameSave>::new(storage);
566
567    let save = GameSave { player_name: "Hero".to_string(), player_level: 7 };
568    manager.save(SaveSlot::Slot1, &save).expect("save");
569    let loaded = manager.load(SaveSlot::Slot1).expect("load");
570    println!("║ Saved: {:?}", save);
571    println!("║ Loaded: {:?}", loaded);
572    assert_eq!(save, loaded);
573    println!("║ ✓ Round-trip verified");
574    println!("╚══════════════════════════════════════════╝");
575}
Source

pub fn save(&self, slot: SaveSlot, data: &S) -> Result<(), SaveError>

Save game data to the given slot.

Serializes the data, appends a checksum, and writes to storage.

Examples found in repository?
examples/hello_dotzuki.rs (line 568)
562fn demo_save_load() {
563    println!("\n╔══ SAVE / LOAD ═════════════════════════╗");
564    let storage = Box::new(InMemoryStorage::new());
565    let manager = SaveManager::<GameSave>::new(storage);
566
567    let save = GameSave { player_name: "Hero".to_string(), player_level: 7 };
568    manager.save(SaveSlot::Slot1, &save).expect("save");
569    let loaded = manager.load(SaveSlot::Slot1).expect("load");
570    println!("║ Saved: {:?}", save);
571    println!("║ Loaded: {:?}", loaded);
572    assert_eq!(save, loaded);
573    println!("║ ✓ Round-trip verified");
574    println!("╚══════════════════════════════════════════╝");
575}
Source

pub fn load(&self, slot: SaveSlot) -> Result<S, SaveError>

Load game data from the given slot.

Reads from storage, validates the checksum, and deserializes.

Examples found in repository?
examples/hello_dotzuki.rs (line 569)
562fn demo_save_load() {
563    println!("\n╔══ SAVE / LOAD ═════════════════════════╗");
564    let storage = Box::new(InMemoryStorage::new());
565    let manager = SaveManager::<GameSave>::new(storage);
566
567    let save = GameSave { player_name: "Hero".to_string(), player_level: 7 };
568    manager.save(SaveSlot::Slot1, &save).expect("save");
569    let loaded = manager.load(SaveSlot::Slot1).expect("load");
570    println!("║ Saved: {:?}", save);
571    println!("║ Loaded: {:?}", loaded);
572    assert_eq!(save, loaded);
573    println!("║ ✓ Round-trip verified");
574    println!("╚══════════════════════════════════════════╝");
575}
Source

pub fn list_slots(&self) -> Vec<(SaveSlot, bool)>

List all slots and whether they contain data.

Source

pub fn delete(&self, slot: SaveSlot) -> Result<(), SaveError>

Delete the save data in the given slot.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for SaveManager<S>

§

impl<S> !Send for SaveManager<S>

§

impl<S> !Sync for SaveManager<S>

§

impl<S> !UnwindSafe for SaveManager<S>

§

impl<S> Freeze for SaveManager<S>

§

impl<S> Unpin for SaveManager<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SaveManager<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.