khonsulabs / bonsaidb

A developer-friendly document database that grows with you, written in Rust
https://bonsaidb.io/
Apache License 2.0
1.01k stars 37 forks source link

Split `Key` into two traits #227

Closed ecton closed 2 years ago

ecton commented 2 years ago

Often it isn't needed to own the Key type, such as when querying a View. The Key type is often dropped after serializing, which means that in many cases when serializing a value, we can get away with borrowed versions. However, due to the Key trait only being implemented for String, for example, it is impossible to pass an &str to be used as a Key.

The goal of this issue is to allow queries to use borrowed representations of String and Vec<u8> when listing collection contents and performing view queries. By only implementing from_ord_bytes for the owned version and having a separate trait for to_ord_bytes, we can allow a wider range of types to be used.