vhbit / lmdb-rs

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

Read-only and read-write Database and Transaction #49

Open cmbrandenburg opened 7 years ago

cmbrandenburg commented 7 years ago

This commit unifies the Transaction and ReadonlyTransaction types into a single Transaction type that is generic with respect to whether the transaction is read-only or read-write. There are two new type definitions, ReadOnlyTransaction and ReadWriteTransaction, which should provide some syntactic sugar for applications.

Similarly, this commit changes the Database type to be generic with respect to read-only vs read-write access, as well as creating two new type definitions, ReadOnlyDatabase and ReadWriteDatabase. Read-only databases only provide non-mutating methods. For example, it will be a compiler error for an application to call the put method on a ReadOnlyDatabase.

cmbrandenburg commented 7 years ago

This pull request does not make the Environment type generic with respect to read-only vs read-write access. I think doing so is a good idea because it would close the remaining loophole in the lmdb-rs type system that allows an application to call database-modifying methods on an environment opened as read-only, but it's unclear to me how the EnvBuilder::open method should be adjusted to make this work. (EDIT: We would also need to make the DbHandle type generic.)

Note that this pull request has nothing to do with issue #48. Whereas, this PR deals with read-only vs read-write access, that issue deals with unsafe lifetimes.