Make LevelDB key type concrete (not generic)

This commit is contained in:
Paul Hauner 2019-05-21 16:49:56 +10:00
parent 54f28df5b1
commit 78368cc2cd
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
2 changed files with 8 additions and 8 deletions

View File

@ -6,11 +6,11 @@ use leveldb::error::Error as LevelDBError;
use leveldb::options::{Options, ReadOptions, WriteOptions}; use leveldb::options::{Options, ReadOptions, WriteOptions};
use std::path::Path; use std::path::Path;
pub struct LevelDB<K: Key> { pub struct LevelDB {
db: Database<K>, db: Database<BytesKey>,
} }
impl<K: Key> LevelDB<K> { impl LevelDB {
pub fn open(path: &Path) -> Result<Self, Error> { pub fn open(path: &Path) -> Result<Self, Error> {
let mut options = Options::new(); let mut options = Options::new();
@ -21,7 +21,7 @@ impl<K: Key> LevelDB<K> {
Ok(Self { db }) Ok(Self { db })
} }
fn read_options(&self) -> ReadOptions<K> { fn read_options(&self) -> ReadOptions<BytesKey> {
ReadOptions::new() ReadOptions::new()
} }
@ -50,7 +50,7 @@ impl Key for BytesKey {
} }
} }
impl Store for LevelDB<BytesKey> { impl Store for LevelDB {
fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<DBValue>, Error> { fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<DBValue>, Error> {
let column_key = Self::get_key_for_col(col, key); let column_key = Self::get_key_for_col(col, key);

View File

@ -5,7 +5,7 @@ mod impls;
mod leveldb_store; mod leveldb_store;
mod memory_db; mod memory_db;
pub use self::leveldb_store::LevelDB; pub use self::leveldb_store::LevelDB as DiskDB;
pub use self::memory_db::MemoryDB; pub use self::memory_db::MemoryDB;
pub use errors::Error; pub use errors::Error;
pub use types::*; pub use types::*;
@ -151,10 +151,10 @@ mod tests {
} }
#[test] #[test]
fn leveldb() { fn diskdb() {
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
let path = dir.path(); let path = dir.path();
let store = LevelDB::open(&path).unwrap(); let store = DiskDB::open(&path).unwrap();
test_impl(store); test_impl(store);
} }