mozilla / rkv

A simple, humane, typed key-value storage solution.
https://crates.io/crates/rkv
Apache License 2.0
307 stars 52 forks source link

Expose NotFound as a specific StoreError #186

Open rnewman opened 4 years ago

rnewman commented 4 years ago

At present a missing key in a .delete call returns StoreError::LmdbError(lmdb::error::Error::NotFound). It is necessary to handle this case specifically in order to implement delete-if-present, which means that consumers need to take a dependency on lmdb-rkv.

One solution for this is to handle NotFound specially in rkv's own interface. I'm open to other suggestions.

dfoxfranke commented 4 years ago

+1. I'd go so far as to say that delete-if-present is the semantics almost everybody wants, and trying to delete a non-existent key should not be considered an error. I propose changing the return type of .delete() to be Result<bool, StoreError>, where the Ok variant is true if the key existed and false if it didn't.