Crates.io | typed-sled |
lib.rs | typed-sled |
version | 0.2.3 |
source | src |
created_at | 2021-09-26 14:21:25.708174 |
updated_at | 2023-01-01 21:37:46.251128 |
description | Sled with types instead of bytes. |
homepage | |
repository | https://github.com/chronicl/typed-sled |
max_upload_size | |
id | 456552 |
size | 166,201 |
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.
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
struct SomeValue(u32);
// Creating a temporary sled database
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");
// insert and get, similar to std's BTreeMap
tree.insert(&"some_key".to_owned(), &SomeValue(10))?;
assert_eq!(tree.get(&"some_key".to_owned())?, Some(SomeValue(10)));
Ok(())
Multiple features for common use cases are available: