-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
413 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "sbv-kv" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
alloy-trie = { workspace = true, optional = true} | ||
sled = { workspace = true, optional = true } | ||
|
||
[features] | ||
sled = ["dep:sled"] | ||
alloy-trie = ["dep:alloy-trie"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use alloy_trie::nodes::TrieNode; | ||
|
||
impl crate::Value for TrieNode { | ||
#[cfg(feature = "sled")] | ||
fn serialize(&self) -> Vec<u8> { | ||
todo!() | ||
} | ||
|
||
#[cfg(feature = "sled")] | ||
fn deserialize(buf: &[u8]) -> Self { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::{KeyValueStore, KeyValueStoreGet, KeyValueStoreInsert, Value}; | ||
use std::borrow::{Borrow, Cow}; | ||
use std::hash::Hash; | ||
|
||
#[cfg(feature = "alloy-trie")] | ||
mod alloy_trie; | ||
#[cfg(feature = "sled")] | ||
mod sled; | ||
mod std_collections; | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value, S: KeyValueStore<K, V>> KeyValueStoreGet<K, V> | ||
for &S | ||
{ | ||
fn get<Q: ?Sized>(&self, k: &Q) -> Option<Cow<V>> | ||
where | ||
K: Borrow<Q>, | ||
Q: Ord + Hash + Eq + AsRef<[u8]>, | ||
{ | ||
S::get(*self, k) | ||
} | ||
} | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value, S: KeyValueStore<K, V>> KeyValueStoreGet<K, V> | ||
for &mut S | ||
{ | ||
fn get<Q: ?Sized>(&self, k: &Q) -> Option<Cow<V>> | ||
where | ||
K: Borrow<Q>, | ||
Q: Ord + Hash + Eq + AsRef<[u8]>, | ||
{ | ||
S::get(*self, k) | ||
} | ||
} | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value, S: KeyValueStore<K, V>> KeyValueStoreInsert<K, V> | ||
for &mut S | ||
{ | ||
fn insert(&mut self, k: K, v: V) { | ||
S::insert(*self, k, v) | ||
} | ||
} | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value, S: KeyValueStore<K, V>> KeyValueStore<K, V> | ||
for &mut S | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{KeyValueStore, KeyValueStoreGet, KeyValueStoreInsert, Value}; | ||
use std::borrow::{Borrow, Cow}; | ||
use std::hash::Hash; | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value> KeyValueStoreInsert<K, V> for sled::Tree { | ||
fn insert(&mut self, k: K, v: V) { | ||
sled::Tree::insert(self, k, v.serialize()).expect("sled io error"); | ||
} | ||
} | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value> KeyValueStoreGet<K, V> for sled::Tree { | ||
fn get<Q: ?Sized>(&self, k: &Q) -> Option<Cow<V>> | ||
where | ||
K: Borrow<Q>, | ||
Q: Ord + Hash + Eq + AsRef<[u8]>, | ||
{ | ||
sled::Tree::get(self, k) | ||
.expect("sled io error") | ||
.map(|vec| Value::deserialize(vec.as_ref())) | ||
.map(Cow::Owned) | ||
} | ||
} | ||
|
||
impl<K: Ord + Hash + Eq + AsRef<[u8]>, V: Value> KeyValueStore<K, V> for sled::Tree {} |
Oops, something went wrong.