pub struct Slot {
pub idx: usize,
pub chksum: Chksum,
pub len: u32,
pub prev: Chksum,
}Expand description
A savegame slot containing metadata about stored data
Each slot represents a savegame header stored in flash memory. Slots form a chain where each new savegame references the previous one via checksums, enabling the scanner to find the most recent valid savegame even after power failures.
§Fields
idx: The slot index in flash memorychksum: Checksum of the savegame datalen: Length of the savegame data in bytesprev: Checksum of the previous savegame (for chain verification)
Fields§
§idx: usize§chksum: Chksum§len: u32§prev: ChksumImplementations§
Source§impl Slot
impl Slot
Sourcepub const HEADER_SIZE: usize = 12usize
pub const HEADER_SIZE: usize = 12usize
Size of the slot header in bytes: two checksums and one length field. The first byte of the checksum is also used to indicate if the slot is in use.
Sourcepub const fn create(idx: usize, prev: Chksum, data: &[u8]) -> Self
pub const fn create(idx: usize, prev: Chksum, data: &[u8]) -> Self
Create a new slot for the given data
Calculates the checksum for the data and creates a slot that references the previous savegame’s checksum.
§Arguments
idx- The slot index where this will be storedprev- The checksum of the previous savegame (or zero for first savegame)data- The savegame data to store
Sourcepub const fn is_valid(&self) -> bool
pub const fn is_valid(&self) -> bool
Check if this slot has valid checksums
A slot is valid if both its checksum and previous checksum have the correct format (most significant bit is zero).
Sourcepub fn is_update_to(&self, other: &Self) -> bool
pub fn is_update_to(&self, other: &Self) -> bool
Check if this slot is an update to another slot
Returns true if this slot’s prev checksum matches the other slot’s checksum,
indicating this is a newer version of the savegame.
Sourcepub fn used_bytes<const SLOT_SIZE: usize>(&self) -> usize
pub fn used_bytes<const SLOT_SIZE: usize>(&self) -> usize
Calculate the total number of bytes used by this savegame
Accounts for the header in the first slot and continuation bytes in subsequent slots if the savegame spans multiple slots.
§Type Parameters
SLOT_SIZE- The size of each slot in bytes
Sourcepub fn next_slot<const SLOT_SIZE: usize, const SLOT_COUNT: usize>(
&self,
) -> usize
pub fn next_slot<const SLOT_SIZE: usize, const SLOT_COUNT: usize>( &self, ) -> usize
Calculate the index of the next free slot after this savegame
Takes into account how many slots this savegame occupies and wraps around using modulo arithmetic.
§Type Parameters
SLOT_SIZE- The size of each slot in bytesSLOT_COUNT- The total number of slots available