Struct agb::save::SaveData

source ·
pub struct SaveData { /* private fields */ }
Expand description

Allows reading and writing of save media.

Implementations§

source§

impl SaveData

source

pub fn media_info(&self) -> &'static MediaInfo

Returns the media info underlying this accessor.

source

pub fn media_type(&self) -> MediaType

Returns the save media type being used.

source

pub fn sector_size(&self) -> usize

Returns the sector size of the save media. It is generally optimal to write data in blocks that are aligned to the sector size.

source

pub fn len(&self) -> usize

Returns the total length of this save media.

source

pub fn read(&mut self, offset: usize, buffer: &mut [u8]) -> Result<(), Error>

Copies data from the save media to a buffer.

If an error is returned, the contents of the buffer are unpredictable.

Examples found in repository?
examples/save.rs (line 20)
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(())
}
source

pub fn verify(&mut self, offset: usize, buffer: &[u8]) -> Result<bool, Error>

Verifies that a given block of memory matches the save media.

source

pub fn align_range(&self, range: Range<usize>) -> Range<usize>

Returns a range that contains all sectors the input range overlaps.

This can be used to calculate which blocks would be erased by a call to prepare_write

source

pub fn prepare_write( &mut self, range: Range<usize> ) -> Result<SavePreparedBlock<'_>, Error>

Prepares a given span of offsets for writing.

This will erase any data in any sector overlapping the input range. To calculate which offset ranges would be affected, use the align_range function.

Examples found in repository?
examples/save.rs (line 24)
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(())
}

Auto Trait Implementations§

§

impl !RefUnwindSafe for SaveData

§

impl Send for SaveData

§

impl Sync for SaveData

§

impl Unpin for SaveData

§

impl !UnwindSafe for SaveData

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.