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
impl InMemoryStorage
Sourcepub fn new() -> Self
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
impl Default for InMemoryStorage
Source§impl SaveStorage for InMemoryStorage
impl SaveStorage for InMemoryStorage
Source§fn 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).
Source§fn read(&self, slot: usize) -> Result<Vec<u8>, SaveError>
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
fn slot_exists(&self, slot: usize) -> bool
Returns
true if the slot contains data.Auto Trait Implementations§
impl !Freeze for InMemoryStorage
impl !RefUnwindSafe for InMemoryStorage
impl !Sync for InMemoryStorage
impl Send for InMemoryStorage
impl Unpin for InMemoryStorage
impl UnsafeUnpin for InMemoryStorage
impl UnwindSafe for InMemoryStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more