vhbit / lmdb-rs

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

Added `ToMdbValue` implementations #54

Open valarauca opened 7 years ago

valarauca commented 7 years ago

Changes

Added 2 new implementations of ToMdbValue for str and [u8] (the non-sized versions without pointers).

Goals

Makes it easier to implement traits like

pub trait GenericLMDBCursor<ActualDBData> {
   type Key: ActualDBData::Key+?Sized;
   type Value: ActualDBData::Value;
   // methods..
}
pub trait ActualDBData {
  type Key: ToMdbValue+?Sized;
  type Value: Message+MessageStatic; //protobuffers
  fn get_db_handle<'a>() -> &'a Database;
}
pub struct DocDB;
impl ActualDBData {
  type Key = str;
  type Value = DocProto;
  fn get_db_handle<'a>() -> &'a Database {
        get_cached_doc_handle()
   }
}

Effectively then I just have one fat trait that does all db stuff on abstract data. And a handful of ZeroSizedTypes which tell me what data I'm using.