Skip to main content

Crate agb_save

Crate agb_save 

Source
Expand description

This crate provides a storage agnostic way to save any serde serialize / deserialize data into save slots like you would find in a classic RPG.

It is opinionated on how the data should be stored and accessed, and expects you to be able to load an entire save slot into RAM at once.

§Example

use agb_save::{SaveSlotManager, StorageMedium};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct SaveData {
    level: u32,
    health: u32,
    inventory: Vec<Item>,
}

#[derive(Serialize, Deserialize)]
struct SaveMetadata {
    player_name: String,
    playtime_seconds: u32,
}

let mut manager = SaveSlotManager::<_, SaveMetadata>::new(
    storage,
    3,  // 3 save slots
    *b"my-game-v1.0____________________",
)?;

// Check slot status before loading
match manager.slot(0) {
    Slot::Empty => println!("Slot 0 is empty"),
    Slot::Valid(metadata) => {
        println!("Player: {}", metadata.player_name);
    }
    Slot::Corrupted => println!("Slot 0 is corrupted"),
}

// Save game
manager.write(0, &save_data, &metadata)?;

// Load game
let save_data: SaveData = manager.read(0)?;

Structs§

SaveSlotManager
A save slot manager which gives you some level of write safety and confirmation that everything worked correctly.
SerializationError
Further details about the serialization error.
StorageInfo
Data about how the StorageMedium should be used.

Enums§

SaveError
Errors that can occur during save operations.
Slot
A save slot with its current state.

Traits§

StorageMedium
Core trait for save storage access.