cberner / redb

An embedded key-value database in pure Rust
https://www.redb.org
Apache License 2.0
3.07k stars 137 forks source link

Support Vec<u8> key values, compatibility with other kv db #797

Closed GopherJ closed 2 months ago

GopherJ commented 3 months ago

redb has its own Key, Value traits but some applications may already do this in their own way and all they need is to be able to store:

Key: Vec\<u8> Value: Vec\<u8>

like other embedded databases, to do this in redb we will need to implement Key for Vec but Vec is an orphan type

Key is implemented for &[u8] but since TableDefinition requires 'static lifetime so we can only use &'static [u8] which is not pratical

lhallam commented 2 months ago

You can use &'static [u8] in the TableDefinition and still insert slices with any lifetime, and get slices with the lifetime of the AccessGuard.

The lifetimes in the TableDefinition are overwritten by the correct lifetime for the context using the associated SelfType defined in Key & Value. e.g. Table::insert is generic over the lifetimes of the key & value, ReadableTable::get is generic over the lifetime of the key and the value has the lifetime of the guard.