diff --git a/src/blake2.rs b/src/blake2.rs index 9c70094..72054a9 100644 --- a/src/blake2.rs +++ b/src/blake2.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. //! Implements the HashWriter interface for the Blake2 hash function. -//! Requires the `blake2` feature to be set. +//! Requires the `blake2` feature to be enabled. use crate::hash::*; use blake2::digest::Digest; diff --git a/src/leveldb/mod.rs b/src/leveldb/mod.rs index ea79434..e826f97 100644 --- a/src/leveldb/mod.rs +++ b/src/leveldb/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. //! Module implementing a store interface using LevelDB for a MerkleDag. -//! Requires the `rusty-leveldb` interface. +//! Requires the `rusty-leveldb` feature to be enabled. use std::cell::RefCell; use std::path::Path; @@ -20,11 +20,13 @@ use std::path::Path; use crate::{ hash::HashWriter, node::Node, - store::{Result, Store, StoreError}, + store::{Result as StoreResult, Store, StoreError}, }; use ciborium; -use rusty_leveldb; +use rusty_leveldb::{self, Options, Status}; + +pub type Result = std::result::Result; /// A `Store` implementation using the rusty-leveldb port of leveldb. /// The Default implementation of this `Default::default()` is an in-memory @@ -34,8 +36,12 @@ pub struct LevelStore { } impl LevelStore { - pub fn open>(path: P) -> std::result::Result { + pub fn open>(path: P) -> Result { let opts = Default::default(); + Self::open_with_opts(path, opts) + } + + pub fn open_with_opts>(path: P, opts: Options) -> Result { Ok(Self { store: RefCell::new(rusty_leveldb::DB::open(path, opts)?), }) @@ -46,11 +52,11 @@ impl Store for LevelStore where HW: HashWriter, { - fn contains(&self, id: &[u8]) -> Result { + fn contains(&self, id: &[u8]) -> StoreResult { Ok(self.store.borrow_mut().get(id).is_some()) } - fn get(&self, id: &[u8]) -> Result>> { + fn get(&self, id: &[u8]) -> StoreResult>> { Ok(match self.store.borrow_mut().get(id) { Some(bs) => ciborium::de::from_reader(bs.as_slice()) .map_err(|e| StoreError::StoreFailure(format!("Invalid serialization {:?}", e)))?, @@ -58,7 +64,7 @@ where }) } - fn store(&mut self, node: Node) -> Result<()> { + fn store(&mut self, node: Node) -> StoreResult<()> { let mut buf = Vec::new(); ciborium::ser::into_writer(&node, &mut buf).unwrap(); self.store.borrow_mut().put(node.id(), &buf)?; diff --git a/src/rocksdb/mod.rs b/src/rocksdb/mod.rs index 1a506c3..9194977 100644 --- a/src/rocksdb/mod.rs +++ b/src/rocksdb/mod.rs @@ -45,8 +45,12 @@ impl RocksStore where TM: ThreadMode, { - pub fn new>(path: P) -> Result { + pub fn open>(path: P) -> Result { let opts = Options::default(); + Self::open_with_opts(path, &opts) + } + + pub fn open_with_opts>(path: P, opts: &Options) -> Result { Ok(Self { store: DBWithThreadMode::::open(&opts, path)?, })