Skip to main content

InMemoryStorage

Struct InMemoryStorage 

Source
pub struct InMemoryStorage { /* private fields */ }
Expand description

An in-memory SaveStorage implementation backed by Vec<Option<Vec<u8>>>.

Intended for use in tests and as a reference implementation.

Implementations§

Source§

impl InMemoryStorage

Source

pub fn new() -> Self

Create a new in-memory storage with 3 empty slots.

Examples found in repository?
examples/hello_dotzuki.rs (line 564)
562fn demo_save_load() {
563    println!("\n╔══ SAVE / LOAD ═════════════════════════╗");
564    let storage = Box::new(InMemoryStorage::new());
565    let manager = SaveManager::<GameSave>::new(storage);
566
567    let save = GameSave { player_name: "Hero".to_string(), player_level: 7 };
568    manager.save(SaveSlot::Slot1, &save).expect("save");
569    let loaded = manager.load(SaveSlot::Slot1).expect("load");
570    println!("║ Saved: {:?}", save);
571    println!("║ Loaded: {:?}", loaded);
572    assert_eq!(save, loaded);
573    println!("║ ✓ Round-trip verified");
574    println!("╚══════════════════════════════════════════╝");
575}

Trait Implementations§

Source§

impl Default for InMemoryStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SaveStorage for InMemoryStorage

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. Read more
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.

Auto Trait Implementations§

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.