vhbit / lmdb-rs

Rust bindings for LMDB
MIT License
114 stars 46 forks source link

Added new trait instances for `ToMdbValue` #53

Closed valarauca closed 7 years ago

valarauca commented 7 years ago

It is rather painful to write a trait which abstracts over types.

The use case I'm attempting to fix is:

trait ApplicationDBs {
  type Key: ToMdbValue;
  type Protobuffer: Message+MessageStatic;
  fn get_db_handle<'a>(&'a self) -> &'a DbHandle;
}
trait CommonDBActions: DBTrans {
   type Key: ToMdbValue;
   type ProtoBuffer: Message+MessageStatic;
   //library boiler plate
}
impl<T: ApplicationDB> CommonDBAction for MyType {
   type Key = T::Key;
   type ProtoBuffer = T::ProtoBuffer;
}

This works great for integers + protobuffers. But I have to expand to strings, byte arrays.