Skip to main content

SaveStorage

Trait SaveStorage 

Source
pub trait SaveStorage {
    // Required methods
    fn write(&self, slot: usize, data: &[u8]) -> Result<(), SaveError>;
    fn read(&self, slot: usize) -> Result<Vec<u8>, SaveError>;
    fn slot_exists(&self, slot: usize) -> bool;
    fn delete_slot(&self, slot: usize) -> Result<(), SaveError>;
}
Expand description

Platform-specific storage backend for save data.

Implementations handle the actual reading and writing of bytes to the underlying medium (e.g. file system, browser localStorage, SRAM chip). Takes &self so implementations must use interior mutability.

Required Methods§

Source

fn write(&self, slot: usize, data: &[u8]) -> Result<(), SaveError>

Write data to the given slot index (0, 1, or 2).

Source

fn read(&self, slot: usize) -> Result<Vec<u8>, SaveError>

Read data from the given slot index.

Returns Err(SaveError::SlotEmpty) if the slot contains no data.

Source

fn slot_exists(&self, slot: usize) -> bool

Returns true if the slot contains data.

Source

fn delete_slot(&self, slot: usize) -> Result<(), SaveError>

Delete data from the given slot index.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§