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 837)
835fn demo_save_load() {
836 println!("\n╔══ SAVE / LOAD ═════════════════════════╗");
837 let storage = Box::new(InMemoryStorage::new());
838 let manager = SaveManager::<GameSave>::new(storage);
839
840 let save = GameSave {
841 player_name: "Hero".to_string(),
842 player_level: 7,
843 };
844 manager.save(SaveSlot::Slot1, &save).expect("save");
845 let loaded = manager.load(SaveSlot::Slot1).expect("load");
846 println!("║ Saved: {:?}", save);
847 println!("║ Loaded: {:?}", loaded);
848 assert_eq!(save, loaded);
849 println!("║ ✓ Round-trip verified");
850 println!("╚══════════════════════════════════════════╝");
851}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