pub trait SlotStore {
// Required methods
fn slot_count(&self) -> u8;
fn capacity(&self, slot: u8) -> Result<u32>;
fn record(&self, slot: u8) -> Result<SlotRecord>;
fn set_record(&mut self, slot: u8, record: SlotRecord) -> Result<()>;
fn erase(&mut self, slot: u8) -> Result<()>;
fn write(&mut self, slot: u8, offset: u32, bytes: &[u8]) -> Result<()>;
fn read(&self, slot: u8, offset: u32, buf: &mut [u8]) -> Result<usize>;
}Expand description
Somewhere to keep images, and the device’s belief about each one.
An implementation must keep the record durable across a reboot. If it does not, a device that loses power mid-update cannot tell what it was doing, which is exactly the situation slots exist to survive.
Required Methods§
Sourcefn slot_count(&self) -> u8
fn slot_count(&self) -> u8
Returns how many slots this device has.
Sourcefn capacity(&self, slot: u8) -> Result<u32>
fn capacity(&self, slot: u8) -> Result<u32>
Returns how many bytes a slot can hold.
§Arguments
slot- the slot to size.
§Returns
The slot’s capacity in bytes.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist.
Sourcefn record(&self, slot: u8) -> Result<SlotRecord>
fn record(&self, slot: u8) -> Result<SlotRecord>
Reads what the device believes about a slot.
§Arguments
slot- the slot to read.
§Returns
The slot’s record.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist.
Sourcefn set_record(&mut self, slot: u8, record: SlotRecord) -> Result<()>
fn set_record(&mut self, slot: u8, record: SlotRecord) -> Result<()>
Writes what the device believes about a slot, durably.
§Arguments
slot- the slot to describe.record- the new record.
§Returns
Ok(()) once the record will survive a reboot.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist.
Sourcefn erase(&mut self, slot: u8) -> Result<()>
fn erase(&mut self, slot: u8) -> Result<()>
Clears a slot’s contents and marks it empty.
§Arguments
slot- the slot to clear.
§Returns
Ok(()) once the slot holds nothing.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist.
Sourcefn write(&mut self, slot: u8, offset: u32, bytes: &[u8]) -> Result<()>
fn write(&mut self, slot: u8, offset: u32, bytes: &[u8]) -> Result<()>
Writes image bytes at an offset within a slot.
§Arguments
slot- the slot to write into.offset- where in the slot the bytes belong.bytes- the bytes to write.
§Returns
Ok(()) once the bytes are stored.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist, or
Refusal::SlotTooSmall if the write would run past the slot’s end.
Sourcefn read(&self, slot: u8, offset: u32, buf: &mut [u8]) -> Result<usize>
fn read(&self, slot: u8, offset: u32, buf: &mut [u8]) -> Result<usize>
Reads image bytes from an offset within a slot.
§Arguments
slot- the slot to read from.offset- where in the slot to start.buf- the destination.
§Returns
How many bytes were read, which is short only at the slot’s end.
§Errors
Returns Refusal::NoSuchSlot if the slot does not exist.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".