Open
Description
The get() method used to return a slice &[u8]
, but that's very difficult to guarantee to work for all libraries. Usually key-value stores offer such a nice interface where the returned value within a transaction can be a slice directly read from the database. However, SQL data cannot do that. Hence, we need to return things by value for them. This is why #652 happened. We now return a Cow
object.
A better way to solve this problem would be by using an associated type in ReadOps, where the return type is defined in the trait's implementation. Something in the form:
pub trait ReadOps: for<'i> PrefixIter<'i> {
type DataType: AsRef<[u8]>;
/// Get value associated with given key.
fn get(&self, idx: DbIndex, key: &[u8]) -> crate::Result<Option<Self::DataType>>;
}