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>
impl<S: Storage> Store<S>
Sourcepub fn new(storage: S) -> Result<Store<S>, (Error, S)>
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.
Sourcepub fn extract_storage(self) -> S
pub fn extract_storage(self) -> S
Extracts the storage.
Sourcepub fn capacity(&self) -> Result<StoreRatio, Error>
pub fn capacity(&self) -> Result<StoreRatio, Error>
Returns the current and total capacity in words.
The capacity represents the size of what is stored.
Sourcepub fn lifetime(&self) -> Result<StoreRatio, Error>
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).
Sourcepub fn transaction<ByteSlice: Borrow<[u8]>>(
&mut self,
updates: &[StoreUpdate<ByteSlice>],
) -> Result<(), Error>
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.
Sourcepub fn clear(&mut self, min_key: usize) -> Result<(), Error>
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.
Sourcepub fn prepare(&mut self, length: usize) -> Result<(), Error>
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.
Sourcepub fn recover(&mut self) -> Result<(), Error>
pub fn recover(&mut self) -> Result<(), Error>
Recovers a possible interrupted operation.
If the storage is completely erased, it is initialized.
Sourcepub fn find(&self, key: usize) -> Result<Option<Vec<u8>>, Error>
pub fn find(&self, key: usize) -> Result<Option<Vec<u8>>, Error>
Returns the value of an entry given its key.
Sourcepub fn find_handle(&self, key: usize) -> Result<Option<StoreHandle>, Error>
pub fn find_handle(&self, key: usize) -> Result<Option<StoreHandle>, Error>
Returns a handle to an entry given its key.
Sourcepub fn insert(&mut self, key: usize, value: &[u8]) -> Result<(), Error>
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.
Sourcepub fn remove(&mut self, key: usize) -> Result<(), Error>
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.
Sourcepub fn remove_handle(&mut self, handle: &StoreHandle) -> Result<(), Error>
pub fn remove_handle(&mut self, handle: &StoreHandle) -> Result<(), Error>
Removes an entry given a handle.
Sourcepub fn max_value_length(&self) -> usize
pub fn max_value_length(&self) -> usize
Returns the maximum length in bytes of a value.
Source§impl Store<BufferStorage>
impl Store<BufferStorage>
Sourcepub fn storage(&self) -> &BufferStorage
pub fn storage(&self) -> &BufferStorage
Accesses the storage.
Sourcepub fn storage_mut(&mut self) -> &mut BufferStorage
pub fn storage_mut(&mut self) -> &mut BufferStorage
Accesses the storage mutably.
Sourcepub fn inspect_value(&self, handle: &StoreHandle) -> Vec<u8> ⓘ
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.
Sourcepub fn apply(
&mut self,
operation: &StoreOperation,
) -> (Vec<StoreHandle>, Result<(), Error>)
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.
Sourcepub fn init_with_cycle(storage: &mut BufferStorage, cycle: usize)
pub fn init_with_cycle(storage: &mut BufferStorage, cycle: usize)
Initializes an erased storage as if it has been erased cycle times.