Crate typed_sled[−][src]
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]:
SearchEngineon top of aTree. - [key_generating]: Create
Trees with automatically generated keys. - [convert]: Convert any
Treeinto anotherTreewith different key and value types. - custom_serde: Create
Trees 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
Support for custom (de)serialization.
Structs
Compare and swap error.
A flash-sympathetic persistent lock-free B+ tree.
Enums
Traits
Trait alias for bounds required on keys and values. For now only types that implement DeserializeOwned are supported.
Functions
The function which is used to deserialize all keys and values.
The function which is used to serialize all keys and values.
