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
impl MicroKV
pub fn in_memory(cred: Credential) -> Result<Self>
pub fn in_memory_with(cred: Credential, config: Config) -> Result<Self>
Sourcepub fn open(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
pub fn open(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
Open, creating the store if it doesn’t exist.
Sourcepub fn open_with(
path: impl AsRef<Path>,
cred: Credential,
config: Config,
) -> Result<Self>
pub fn open_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>
MicroKV::open with explicit Config.
Sourcepub fn open_existing(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
pub fn open_existing(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
Fails if the store doesn’t exist.
Sourcepub fn open_existing_with(
path: impl AsRef<Path>,
cred: Credential,
config: Config,
) -> Result<Self>
pub fn open_existing_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>
MicroKV::open_existing with explicit Config.
Sourcepub fn create_new(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
pub fn create_new(path: impl AsRef<Path>, cred: Credential) -> Result<Self>
Fails if the store already exists.
Sourcepub fn create_new_with(
path: impl AsRef<Path>,
cred: Credential,
config: Config,
) -> Result<Self>
pub fn create_new_with( path: impl AsRef<Path>, cred: Credential, config: Config, ) -> Result<Self>
MicroKV::create_new with explicit Config.
Sourcepub fn namespace(&self, name: impl AsRef<str>) -> Tree
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.
Sourcepub fn tree_names(&self) -> Result<Vec<String>>
pub fn tree_names(&self) -> Result<Vec<String>>
Namespaces that currently hold data.
Sourcepub fn transaction<F, R>(&self, f: F) -> Result<R>
pub fn transaction<F, R>(&self, f: F) -> 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).
pub fn kdf_params(&self) -> KdfParams
Sourcepub fn change_password(
&self,
old: impl Into<String>,
new: impl Into<String>,
) -> Result<()>
pub fn change_password( &self, old: impl Into<String>, new: impl Into<String>, ) -> Result<()>
Verify old, then re-key everything under new.
Sourcepub fn rekey(&self, new: Credential) -> Result<()>
pub fn rekey(&self, new: Credential) -> Result<()>
Re-derive the key from new (fresh salt) and re-encrypt every entry + the verifier.
Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Persist to the store’s path; errors (Error::NoPath) for in-memory stores.
Sourcepub fn save_as(&self, path: impl AsRef<Path>) -> Result<()>
pub fn save_as(&self, path: impl AsRef<Path>) -> Result<()>
Persist a copy elsewhere, leaving the store’s own path unchanged.
Sourcepub fn sweep_expired(&self) -> Result<usize>
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>§
pub fn get<V: DeserializeOwned>(&self, key: &str) -> Result<Option<V>>
pub fn require<V: DeserializeOwned>(&self, key: &str) -> Result<V>
Sourcepub fn get_secret<V: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<Secret<V>>>
pub fn get_secret<V: DeserializeOwned>( &self, key: &str, ) -> Result<Option<Secret<V>>>
pub fn put<V: Serialize>(&self, key: &str, value: &V) -> Result<()>
pub fn put_with_ttl<V: Serialize>( &self, key: &str, value: &V, ttl: Duration, ) -> Result<()>
pub fn remove(&self, key: &str) -> Result<bool>
pub fn contains(&self, key: &str) -> Result<bool>
pub fn len(&self) -> Result<usize>
pub fn is_empty(&self) -> Result<bool>
Sourcepub fn update<V, F>(&self, key: &str, f: F) -> Result<()>
pub fn update<V, F>(&self, key: &str, f: F) -> Result<()>
Atomic read-modify-write under one lock. Returning None removes the key.
pub fn get_or_insert_with<V, F>(&self, key: &str, f: F) -> Result<V>
Sourcepub fn compare_and_swap<V: Serialize + DeserializeOwned>(
&self,
key: &str,
expected: Option<&V>,
new: Option<&V>,
) -> Result<bool>
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).
pub fn keys_sorted(&self) -> Result<Vec<String>>
Sourcepub fn prefix<V: DeserializeOwned>(
&self,
prefix: &str,
) -> Result<Vec<(String, V)>>
pub fn prefix<V: DeserializeOwned>( &self, prefix: &str, ) -> Result<Vec<(String, V)>>
Entries whose key starts with prefix (decrypts each match).
Sourcepub fn for_each<V, F>(&self, f: F) -> Result<()>
pub fn for_each<V, F>(&self, f: F) -> Result<()>
Visit every live entry; return Break to stop early.