Struct agb::save::SavePreparedBlock
source · pub struct SavePreparedBlock<'a> { /* private fields */ }
Expand description
A block of save memory that has been prepared for writing.
Implementations§
source§impl<'a> SavePreparedBlock<'a>
impl<'a> SavePreparedBlock<'a>
sourcepub fn write(&mut self, offset: usize, buffer: &[u8]) -> Result<(), Error>
pub fn write(&mut self, offset: usize, buffer: &[u8]) -> Result<(), Error>
Writes a given buffer into the save media.
Multiple overlapping writes to the same memory range without a separate
call to prepare_write
will leave the save data in an unpredictable
state. If an error is returned, the contents of the save media is
unpredictable.
Examples found in repository?
examples/save.rs (line 25)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn test_save(mut gba: agb::Gba) -> Result<(), Error> {
gba.save.init_sram();
let mut access = gba.save.access()?;
let mut is_save = 0;
access.read(0, core::slice::from_mut(&mut is_save))?;
if is_save != 0 {
access
.prepare_write(0..128)?
.write(0, &(0..128).collect::<Vec<_>>())?;
}
Ok(())
}
sourcepub fn write_and_verify(
&mut self,
offset: usize,
buffer: &[u8]
) -> Result<(), Error>
pub fn write_and_verify( &mut self, offset: usize, buffer: &[u8] ) -> Result<(), Error>
Writes and validates a given buffer into the save media.
This function will verify that the write has completed successfully, and return an error if it has not done so.
Multiple overlapping writes to the same memory range without a separate
call to prepare_write
will leave the save data in an unpredictable
state. If an error is returned, the contents of the save media is
unpredictable.