vhbit / lmdb-rs

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

Add blanket implementation(s) #34

Open iqualfragile opened 8 years ago

iqualfragile commented 8 years ago

It would be nice to be able to insert and retrieve values more easily, therefore i propose to include a (extremly trivial) blanket implementation for ToMdbValue and/or FromMdbValue for everything that implements the serde Serialize and/or Deserialize trait using for examble bincode for serialisation.

xitep commented 8 years ago

Hm, I'm not really convinced it is worth the 3rd party dependencies. However, I could imagine this to be an optional feature.

  1. How would lmdb-rs deal with the fact that serialization/deserialization can fail for some reason? Even today the FromMdbValue implementation for String (uses .unwrap()) and &str (might produce an invalid utf8 string) is problematic.
  2. How difficult is to read such encoded data from other programming languages?
iqualfragile commented 8 years ago

the reason im asking you to implement this over just doing it myself is because i literally can not do that. Rust disallows me to, because both Traits are from foreign crates. Yes, as an optional, compile-time-enabled feature would be the right way to go, especially as currently both serde and rustc-serialize exist and support for both might be positive.

  1. I would just panic. Im not quite sure how serialization could fail besides going out of memory, which is a crash in things like arrays, too. Deserialization could in fact fail, but you do not expect your database to contain corrupted data, thats just not something you are gona code for. External input, ok, but the database that you just wrote to now containing broken data, no.
  2. That depends on which serialization is used. Maybe allowing two options there would be a good idea. Bincode for a space-efficient encoding, and json/some kind of slightly binarized json for interoperability. I do believe that the main use case for a local memory mapped key-value database is in fact using it with the same software.