Slot

Struct Slot 

Source
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 memory
  • chksum: Checksum of the savegame data
  • len: Length of the savegame data in bytes
  • prev: Checksum of the previous savegame (for chain verification)

Fields§

§idx: usize§chksum: Chksum§len: u32§prev: Chksum

Implementations§

Source§

impl Slot

Source

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.

Source

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 stored
  • prev - The checksum of the previous savegame (or zero for first savegame)
  • data - The savegame data to store
Source

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).

Source

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.

Source

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
Source

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 bytes
  • SLOT_COUNT - The total number of slots available
Source

pub fn to_bytes(&self) -> [u8; 12]

Serialize the slot header to bytes for writing to flash

The format is: checksum (4 bytes) + length (4 bytes) + prev checksum (4 bytes)

Source

pub fn from_bytes(idx: usize, bytes: [u8; 12]) -> Self

Deserialize a slot header from bytes

§Arguments
  • idx - The slot index where this header was read from
  • bytes - The header bytes in the format: checksum + length + prev checksum

Trait Implementations§

Source§

impl Debug for Slot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Slot

Source§

fn eq(&self, other: &Slot) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Slot

Auto Trait Implementations§

§

impl Freeze for Slot

§

impl RefUnwindSafe for Slot

§

impl Send for Slot

§

impl Sync for Slot

§

impl Unpin for Slot

§

impl UnwindSafe for Slot

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.