ekv

Crates

git

Versions

default

Flavors

ekv

Struct 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 DerefMut<Target = F> + '_

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> !Freeze for Database<F, M>

§

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

§

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

§

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

§

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

§

impl<F, M> UnwindSafe for Database<F, M>
where M: UnwindSafe, 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 = 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.