levilamina::kvdb¶
The key-value store: a mod's own persistent storage.
This family is thread safe
The ABI marks kvdb_* as internally locked, one of the exceptions of contract Β§4, so any thread
may call it. Almost every other domain works on the server thread alone, and this is one of the
few usable straight from a std::thread::spawn.
Paths are confined to the mod's own data directory
The host refuses .. and an absolute path. The host owns the handle, force-closes it when the
mod unloads and warns, so forgetting to close loses no data while leaving a trace in the log.
KvDb¶
One open key-value store. Dropping it closes it.
- Implements:
Send,Sync,Drop,Debug
KvDb::open¶
| Rust | |
|---|---|
Opens it, creating it when it does not exist.
- Parameters:
- path :
&str
- path :
- Return type:
Result<KvDb> - Slots:
kvdb_open
KvDb::open_existing¶
| Rust | |
|---|---|
Opens an existing one only. A store that does not exist is an Err and no empty one is
quietly created: reading a store that should hold data and creating a new one are two
different things.
- Parameters:
- path :
&str
- path :
- Return type:
Result<KvDb> - Slots:
kvdb_open
KvDb::path¶
| Rust | |
|---|---|
- Return type:
&str
KvDb::try_get¶
| Rust | |
|---|---|
Reads one key: Ok(None) for a key that does not exist, Err for a host without
kvdb_get. A database the host closed on its own, at an unload, also reads as
Ok(None): the slot answers both with the same false, and the ABI cannot tell them
apart.
Both gates apply even after open has succeeded: kvdb_get sits after kvdb_open in
the table at a larger offset, and the first being covered does not imply the second is.
- Parameters:
- key :
&str
- key :
- Return type:
Result<Option<String>> - Slots:
kvdb_get
KvDb::get¶
| Rust | |
|---|---|
Reads one key, with None for every case KvDb::try_get keeps apart.
- Parameters:
- key :
&str
- key :
- Return type:
Option<String> - Slots:
kvdb_get
KvDb::set¶
| Rust | |
|---|---|
- Parameters:
- key :
&str - value :
&str
- key :
- Return type:
Result<()> - Slots:
kvdb_set
KvDb::del¶
| Rust | |
|---|---|
Deletes one key. A key that never existed also counts as a success.
- Parameters:
- key :
&str
- key :
- Return type:
Result<()> - Slots:
kvdb_del
KvDb::has¶
| Rust | |
|---|---|
KvDb::is_empty¶
| Rust | |
|---|---|
- Return type:
bool - Slots:
kvdb_is_empty,kvdb_is_empty
KvDb::iter¶
| Rust | |
|---|---|
Every key-value pair. The whole store is read into memory, so a large one needs care.