Embassy
ekv

Crates

git

Versions

default

Flavors

Struct ekv::Database

source ·
pub struct Database<F: Flash, M: RawMutex> { /* private fields */ }
Expand description

The main database struct.

Implementations§

source§

impl<F: Flash, M: RawMutex> Database<F, M>

source

pub fn new(flash: F, config: Config) -> Self

Create a new database.

This does no flash operations, and always succeeds. Actually mounting the database is done lazily, when the first operation (read or write) is done.

If the storage is not formatted, you have to call format before first use.

You can call mount to force eagerly mounting the database. This can be useful to detect whether the storage is formatted or not, so that you can format it if it isn’t before first use.

source

pub async fn lock_flash(&self) -> impl Deref<Target = F> + DerefMut + '_

Get an exclusive lock for the underlying flash.

This returns a “mutex guard”-like object that gives exclusive access to the flash. All other concurrent operations on the database will wait on this object to be dropped.

Note that actually writing to the flash behind ekv’s back will result in corruption. This is intended for other tasks, for example reading the flash memory’s serial number, or statistics.

source

pub async fn format(&self) -> Result<(), FormatError<F::Error>>

Format the database storage.

This will format the underlying storage into an empty key-value database. If the storage was already formatted, all data will be lost.

source

pub async fn mount(&self) -> Result<(), MountError<F::Error>>

Force eagerly mounting the database storage.

You don’t have to call this method, mounting is done lazily on first operation.

Eagerly mounting can still be useful, to detect whether the storage is formatted or not, so that you can format it if it isn’t before first use.

source

pub async fn read_transaction(&self) -> ReadTransaction<'_, F, M>

Open a read transaction.

This will wait if there’s a write transaction either being currently committed, or waiting to be committed because there are other read transactions open.

Dropping the ReadTransaction closes the transaction. Make sure to drop it as soon as possible, to not delay write transaction commits.

source

pub async fn write_transaction(&self) -> WriteTransaction<'_, F, M>

Open a write transaction.

This will wait if there’s another write transaction already open.

To make all the writes permanent, call commit. Dropping the WriteTransaction without committing closes the transaction and discards all written data.

Auto Trait Implementations§

§

impl<F, M> !RefUnwindSafe for Database<F, M>

§

impl<F, M> Send for Database<F, M>where F: Send, M: Send,

§

impl<F, M> Sync for Database<F, M>where F: Send, M: Sync,

§

impl<F, M> Unpin for Database<F, M>where F: Unpin, M: Unpin,

§

impl<F, M> UnwindSafe for Database<F, M>where F: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.