Skip to main content

MicroKV

Struct MicroKV 

Source
pub struct MicroKV { /* private fields */ }
Expand description

The database handle. Cheap to clone (Arc-backed); all clones share one store.

Operations on the default namespace (get, put, keys, …) are available directly via Deref to the default Tree; store-wide operations (namespace, transaction, save, rekey, …) are inherent methods.

Implementations§

Source§

impl MicroKV

Source

pub fn in_memory(cred: Credential) -> Result<Self>

Source

pub fn in_memory_with(cred: Credential, config: Config) -> Result<Self>

Source

pub fn open(path: impl AsRef<Path>, cred: Credential) -> Result<Self>

Open, creating the store if it doesn’t exist.

Source

pub fn open_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>

MicroKV::open with explicit Config.

Source

pub fn open_existing(path: impl AsRef<Path>, cred: Credential) -> Result<Self>

Fails if the store doesn’t exist.

Source

pub fn open_existing_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>

Source

pub fn create_new(path: impl AsRef<Path>, cred: Credential) -> Result<Self>

Fails if the store already exists.

Source

pub fn create_new_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>

MicroKV::create_new with explicit Config.

Source

pub fn namespace(&self, name: impl AsRef<str>) -> Tree

An isolated namespace: keys never collide across namespaces, and each value’s ciphertext is bound to its namespace. MicroKV derefs to the default ("") one.

Source

pub fn tree_names(&self) -> Result<Vec<String>>

Namespaces that currently hold data.

Source

pub fn transaction<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&mut Txn<'_>) -> Result<R>,

Run ops under one write lock against a working copy: commit on Ok, roll back on Err. Namespaces are explicit ("" is the default).

Source

pub fn kdf_params(&self) -> KdfParams

Source

pub fn change_password( &self, old: impl Into<String>, new: impl Into<String>, ) -> Result<()>

Verify old, then re-key everything under new.

Source

pub fn rekey(&self, new: Credential) -> Result<()>

Re-derive the key from new (fresh salt) and re-encrypt every entry + the verifier.

Source

pub fn save(&self) -> Result<()>

Persist to the store’s path; errors (Error::NoPath) for in-memory stores.

Source

pub fn save_as(&self, path: impl AsRef<Path>) -> Result<()>

Persist a copy elsewhere, leaving the store’s own path unchanged.

Source

pub fn export(&self) -> Result<Vec<u8>>

The encrypted store as bytes (no filesystem access).

Source

pub fn destroy(self) -> Result<()>

Clear all data and delete the file + its .lock sidecar.

Source

pub fn sweep_expired(&self) -> Result<usize>

Drop every expired entry, returning the count. Entries are authenticated before their (encrypted) expiry is trusted, so a tampered expiry errors instead of dropping a live value.

Methods from Deref<Target = Tree>§

Source

pub fn name(&self) -> &str

"" for the default namespace.

Source

pub fn get<V: DeserializeOwned>(&self, key: &str) -> Result<Option<V>>

Source

pub fn require<V: DeserializeOwned>(&self, key: &str) -> Result<V>

Source

pub fn get_secret<V: DeserializeOwned>( &self, key: &str, ) -> Result<Option<Secret<V>>>

Tree::get, wrapped in a non-logging Secret.

Source

pub fn put<V: Serialize>(&self, key: &str, value: &V) -> Result<()>

Source

pub fn put_with_ttl<V: Serialize>( &self, key: &str, value: &V, ttl: Duration, ) -> Result<()>

Source

pub fn remove(&self, key: &str) -> Result<bool>

Source

pub fn contains(&self, key: &str) -> Result<bool>

Source

pub fn len(&self) -> Result<usize>

Source

pub fn is_empty(&self) -> Result<bool>

Source

pub fn update<V, F>(&self, key: &str, f: F) -> Result<()>
where V: Serialize + DeserializeOwned, F: FnOnce(Option<V>) -> Option<V>,

Atomic read-modify-write under one lock. Returning None removes the key.

Source

pub fn get_or_insert_with<V, F>(&self, key: &str, f: F) -> Result<V>
where V: Serialize + DeserializeOwned, F: FnOnce() -> V,

Source

pub fn compare_and_swap<V: Serialize + DeserializeOwned>( &self, key: &str, expected: Option<&V>, new: Option<&V>, ) -> Result<bool>

Swap to new only if the current value equals expected (by serialized bytes).

Source

pub fn keys(&self) -> Result<Vec<String>>

Live keys (expired entries excluded).

Source

pub fn keys_sorted(&self) -> Result<Vec<String>>

Source

pub fn prefix<V: DeserializeOwned>( &self, prefix: &str, ) -> Result<Vec<(String, V)>>

Entries whose key starts with prefix (decrypts each match).

Source

pub fn for_each<V, F>(&self, f: F) -> Result<()>
where V: DeserializeOwned, F: FnMut(&str, V) -> ControlFlow<()>,

Visit every live entry; return Break to stop early.

Source

pub fn clear(&self) -> Result<()>

Trait Implementations§

Source§

impl Clone for MicroKV

Source§

fn clone(&self) -> MicroKV

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

impl Debug for MicroKV

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for MicroKV

Source§

type Target = Tree

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Tree

Dereferences the value.

Auto Trait Implementations§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.