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§
Sourcefn write(&self, slot: usize, data: &[u8]) -> Result<(), SaveError>
fn write(&self, slot: usize, data: &[u8]) -> Result<(), SaveError>
Write data to the given slot index (0, 1, or 2).
Sourcefn read(&self, slot: usize) -> Result<Vec<u8>, SaveError>
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.
Sourcefn slot_exists(&self, slot: usize) -> bool
fn slot_exists(&self, slot: usize) -> bool
Returns true if the slot contains data.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".