ariel_os::storage

Struct Storage

pub struct Storage<F> { /* private fields */ }
Available on crate feature storage only.
Expand description

Object holding an instance of a key-value pair storage.

You should probably look into using the global instance accessible via ariel_os_storage::storage::{get,insert,remove}.

Implementations§

§

impl<F> Storage<F>
where F: NorFlash,

pub const fn new(flash: F, storage_range: Range<u32>) -> Storage<F>

Creates a new Storage instance.

pub async fn get_raw<V>( &mut self, key: &str, ) -> Result<Option<V>, Error<<F as ErrorType>::Error>>
where V: for<'d> Value<'d>,

Gets a [Value] from this Storage instance.

§Panics

Currently panics if key.len() > MAX_KEY_LEN.

pub async fn insert_raw<'d, V>( &mut self, key: &str, value: V, ) -> Result<(), Error<<F as ErrorType>::Error>>
where V: Value<'d>,

Inserts a [Value] into this Storage instance.

§Panics

Currently panics if key.len() > MAX_KEY_LEN.

pub async fn insert<'d, V>( &mut self, key: &str, value: V, ) -> Result<(), Error<<F as ErrorType>::Error>>
where V: Serialize + Deserialize<'d> + Into<PostcardValue<V>>,

Stores a key-value pair into flash memory.

It will overwrite the last value that has the same key.

pub async fn get<V>( &mut self, key: &str, ) -> Result<Option<V>, Error<<F as ErrorType>::Error>>
where V: Serialize + for<'d> Deserialize<'d> + Into<PostcardValue<V>>,

Gets the last stored value from the flash that is associated with the given key.

If no value with the key is found, None is returned.

§Panics

Currently panics if key.len() > MAX_KEY_LEN.

pub async fn erase_all(&mut self) -> Result<(), Error<<F as ErrorType>::Error>>

Resets the flash in the entire flash range of this Storage instance.

§

impl<F> Storage<F>
where F: MultiwriteNorFlash,

pub async fn remove( &mut self, key: &str, ) -> Result<(), Error<<F as ErrorType>::Error>>

Deletes an item from flash.

Additional calls to Storage::get() with the same key will return None until a new one is stored again.

This is really slow!

All items in flash have to be read and deserialized to find the items with the key. This is unlikely to be cached well.

§Panics

Currently panics if key.len() > MAX_KEY_LEN.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<F> UnwindSafe for Storage<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.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

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

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V