Skip to main content

Partition

Struct Partition 

Source
pub struct Partition<F> { /* private fields */ }
Expand description

A NorFlash view of [base, base + len) of an underlying device.

Offsets passed to the flash traits are relative to base, and the reported capacity is len. Alignment granularity, and every error the device itself raises, pass through unchanged.

See the module documentation for why the two constructors exist.

Implementations§

Source§

impl<F: NorFlash> Partition<F>

Source

pub fn new(inner: F, base: u32, len: u32) -> Result<Self, Error>

Create a partition covering [base, base + len) of inner.

§Errors
  • InvalidConfig if len is zero, if base or len is not a multiple of the device’s erase, write and read granularity, or if the range runs past the device’s capacity
  • Overflow if base + len does not fit in u32
Source§

impl<F: NorFlash> Partition<F>

Source

pub fn new_async(inner: F, base: u32, len: u32) -> Result<Self, Error>

Available on crate feature async only.

Create a partition over a device implementing the async flash traits.

Not an async fn — see the module documentation for why the suffix is there. Validation is otherwise identical to new.

Source§

impl<F> Partition<F>

Source

pub const fn base(&self) -> u32

First byte of the partition in the underlying device’s address space.

Source

pub const fn len(&self) -> u32

Length of the partition in bytes.

Source

pub const fn is_empty(&self) -> bool

Whether the partition is empty. Never true — a zero length is rejected at construction — but clippy asks for it wherever len exists.

Source

pub const fn end(&self) -> u32

Byte after the last byte of the partition.

Source

pub const fn contains(&self, addr: u32) -> bool

Whether addr, an address in the underlying device’s space, falls inside this partition.

Source

pub const fn inner(&self) -> &F

Borrow the underlying device.

Source

pub const fn inner_mut(&mut self) -> &mut F

Borrow the underlying device mutably.

This is the escape hatch out of the partition, and it is deliberately explicit: everything reached through here is addressed in the device’s space, with no bound of any kind.

Source

pub fn into_inner(self) -> F

Consume the partition and return the underlying device.

Trait Implementations§

Source§

impl<F> Debug for Partition<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: ErrorType> ErrorType for Partition<F>

Source§

type Error = PartitionError<<F as ErrorType>::Error>

Errors returned by this NOR flash.
Source§

impl<F> Format for Partition<F>

Available on crate feature defmt only.
Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl<F: NorFlash> NorFlash for Partition<F>

Source§

const WRITE_SIZE: usize = F::WRITE_SIZE

The minumum number of bytes the storage peripheral can write
Source§

const ERASE_SIZE: usize = F::ERASE_SIZE

The minumum number of bytes the storage peripheral can erase
Source§

fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error>

Erase the given storage range, clearing all data within [from..to]. The given range will contain all 1s afterwards. Read more
Source§

fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>

If power is lost during write, the contents of the written words are undefined, but the rest of the page is guaranteed to be unchanged. It is not allowed to write to the same word twice. Read more
Source§

impl<F: NorFlash> NorFlash for Partition<F>

Available on crate feature async only.
Source§

const WRITE_SIZE: usize = F::WRITE_SIZE

The minumum number of bytes the storage peripheral can write
Source§

const ERASE_SIZE: usize = F::ERASE_SIZE

The minumum number of bytes the storage peripheral can erase
Source§

async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error>

Erase the given storage range, clearing all data within [from..to]. The given range will contain all 1s afterwards. Read more
Source§

async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>

If power is lost during write, the contents of the written words are undefined, but the rest of the page is guaranteed to be unchanged. It is not allowed to write to the same word twice. Read more
Source§

impl<F: ReadNorFlash> ReadNorFlash for Partition<F>

Source§

const READ_SIZE: usize = F::READ_SIZE

The minumum number of bytes the storage peripheral can read
Source§

fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>

Read a slice of data from the storage peripheral, starting the read operation at the given address offset, and reading bytes.len() bytes. Read more
Source§

fn capacity(&self) -> usize

The capacity of the peripheral in bytes.
Source§

impl<F: ReadNorFlash> ReadNorFlash for Partition<F>

Available on crate feature async only.
Source§

const READ_SIZE: usize = F::READ_SIZE

The minumum number of bytes the storage peripheral can read
Source§

async fn read( &mut self, offset: u32, bytes: &mut [u8], ) -> Result<(), Self::Error>

Read a slice of data from the storage peripheral, starting the read operation at the given address offset, and reading bytes.len() bytes. Read more
Source§

fn capacity(&self) -> usize

The capacity of the peripheral in bytes.
Source§

impl<F: Removable> Removable for Partition<F>

Source§

fn is_present(&self) -> bool

Returns true while the medium is believed present and usable.

Auto Trait Implementations§

§

impl<F> Freeze for Partition<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Partition<F>
where F: RefUnwindSafe,

§

impl<F> Send for Partition<F>
where F: Send,

§

impl<F> Sync for Partition<F>
where F: Sync,

§

impl<F> Unpin for Partition<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for Partition<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for Partition<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.