Skip to main content

Store

Struct Store 

Source
pub struct Store<S: Storage> { /* private fields */ }
Expand description

Implements a store with a map interface over a storage.

Implementations§

Source§

impl<S: Storage> Store<S>

Source

pub fn new(storage: S) -> Result<Store<S>, (Error, S)>

Resumes or initializes a store for a given storage.

If the storage is completely erased, it is initialized. Otherwise, a possible interrupted operation is recovered by being either completed or rolled-back. In case of error, the storage ownership is returned.

§Errors

Returns INVALID_ARGUMENT if the storage is not supported.

Source

pub fn extract_storage(self) -> S

Extracts the storage.

Source

pub fn iter(&self) -> Result<StoreIter<'_>, Error>

Iterates over the entries.

Source

pub fn capacity(&self) -> Result<StoreRatio, Error>

Returns the current and total capacity in words.

The capacity represents the size of what is stored.

Source

pub fn lifetime(&self) -> Result<StoreRatio, Error>

Returns the current and total lifetime in words.

The lifetime represents the age of the storage. The limit is an over-approximation by at most the maximum length of a value (the actual limit depends on the length of the prefix of the first physical page once all its erase cycles have been used).

Source

pub fn transaction<ByteSlice: Borrow<[u8]>>( &mut self, updates: &[StoreUpdate<ByteSlice>], ) -> Result<(), Error>

Applies a sequence of updates as a single transaction.

§Errors

Returns INVALID_ARGUMENT in the following circumstances:

  • There are too many updates.
  • The updates overlap, i.e. their keys are not disjoint.
  • The updates are invalid, e.g. key out of bound or value too long.
Source

pub fn clear(&mut self, min_key: usize) -> Result<(), Error>

Removes multiple entries as part of a single transaction.

Entries with a key larger or equal to min_key are deleted.

Source

pub fn prepare(&mut self, length: usize) -> Result<(), Error>

Compacts the store once if needed.

If the immediate capacity is at least length words, then nothing is modified. Otherwise, one page is compacted.

Source

pub fn recover(&mut self) -> Result<(), Error>

Recovers a possible interrupted operation.

If the storage is completely erased, it is initialized.

Source

pub fn find(&self, key: usize) -> Result<Option<Vec<u8>>, Error>

Returns the value of an entry given its key.

Source

pub fn find_handle(&self, key: usize) -> Result<Option<StoreHandle>, Error>

Returns a handle to an entry given its key.

Source

pub fn insert(&mut self, key: usize, value: &[u8]) -> Result<(), Error>

Inserts an entry in the store.

If an entry for the same key is already present, it is replaced.

Source

pub fn remove(&mut self, key: usize) -> Result<(), Error>

Removes an entry given its key.

This is not an error if there is no entry for this key.

Source

pub fn remove_handle(&mut self, handle: &StoreHandle) -> Result<(), Error>

Removes an entry given a handle.

Source

pub fn max_value_length(&self) -> usize

Returns the maximum length in bytes of a value.

Source§

impl Store<BufferStorage>

Source

pub fn format(&self) -> &Format

Returns the storage configuration.

Source

pub fn storage(&self) -> &BufferStorage

Accesses the storage.

Source

pub fn storage_mut(&mut self) -> &mut BufferStorage

Accesses the storage mutably.

Source

pub fn inspect_value(&self, handle: &StoreHandle) -> Vec<u8>

Returns the value of a possibly deleted entry.

If the value has been partially compacted, only return the non-compacted part. Returns an empty value if it has been fully compacted.

Source

pub fn apply( &mut self, operation: &StoreOperation, ) -> (Vec<StoreHandle>, Result<(), Error>)

Applies an operation and returns the deleted entries.

Note that the deleted entries are before any compaction, so they may point outside the window. This is more expressive than returning the deleted entries after compaction since compaction can be controlled independently.

Source

pub fn init_with_cycle(storage: &mut BufferStorage, cycle: usize)

Initializes an erased storage as if it has been erased cycle times.

Trait Implementations§

Source§

impl<S: Clone + Storage> Clone for Store<S>

Source§

fn clone(&self) -> Store<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Store<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Store<S>
where S: RefUnwindSafe,

§

impl<S> Send for Store<S>
where S: Send,

§

impl<S> Sync for Store<S>
where S: Sync,

§

impl<S> Unpin for Store<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Store<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Store<S>
where S: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.