Expand description
typed-sled - a database build on top of sled.
sled is a high-performance embedded database with an API that is similar to a BTreeMap<[u8], [u8]>
.
typed-sled builds on top of sled and offers an API that is similar to a BTreeMap<K, V>
, where
K and V are user defined types which implement Deserialize and Serialize.
§features
Multiple features for common use cases are also available:
- [search]:
SearchEngine
on top of aTree
. - [key_generating]: Create
Tree
s with automatically generated keys. - [convert]: Convert any
Tree
into anotherTree
with different key and value types. - custom_serde: Create
Tree
s with custom (de)serialization. This for example makes lazy or zero-copy (de)serialization possible.
§Example
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
struct SomeValue(u32);
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Creating a temporary sled database.
// If you want to persist the data use sled::open instead.
let db = sled::Config::new().temporary(true).open().unwrap();
// The id is used by sled to identify which Tree in the database (db) to open
let tree = typed_sled::Tree::<String, SomeValue>::open(&db, "unique_id");
tree.insert(&"some_key".to_owned(), &SomeValue(10))?;
assert_eq!(tree.get(&"some_key".to_owned())?, Some(SomeValue(10)));
Ok(())
}
Modules§
- custom_
serde - Support for custom (de)serialization.
- transaction
Structs§
- Batch
- Compare
AndSwap Error - Compare and swap error.
- Config
- Top-level configuration for the system.
- Iter
- Subscriber
- Tree
- A flash-sympathetic persistent lock-free B+ tree.
Enums§
Traits§
- KV
- Trait alias for bounds required on keys and values. For now only types that implement DeserializeOwned are supported.
- Merge
Operator - Examples
Functions§
- deserialize
- The function which is used to deserialize all keys and values.
- open
- Opens a
Db
with a default configuration at the specified path. This will create a new storage directory at the specified path if it does not already exist. You can use theDb::was_recovered
method to determine if your database was recovered from a previous instance. You can useConfig::create_new
if you want to increase the chances that the database will be freshly created. - serialize
- The function which is used to serialize all keys and values.