-
Notifications
You must be signed in to change notification settings - Fork 54
Why so many traits? #27
Copy link
Copy link
Open
Description
I'm wondering why there are so many traits in the crate. Traits are used for abstractions, but from what I've seen they don't abstract anything. Wouldn't it be simpler to not have them? Or, if abstraction is desirable, move the traits into separate crate and generalize them little bit more. This way they could be implemented for various databases. (So people who want to use other databases don't need to have leveldb in their dependencies.)
I imagine something like this:
trait KVDatabase {
type BorrowedKey;
/// Value that is returned from `get` method
type OwnedValue: Borrow<Self::BorrowedValue>;
/// Value that can be passed to `put` and `delete` methods
type BorrowedValue;
type GetError;
type PutError;
type DeleteError;
fn get(&self, &Self::BorrowedKey) -> Result<Option<Self::OwnedValue>, Self::GetError>;
fn put(&mut self, &Self::BorrowedKey, Self::BorrowedValue) -> Result<(), Self::PutError>;
fn delete(&mut self, &Self::BorrowedKey) -> Result<bool, Self::DeleteError>;
}
trait IterKVDatabase: KVDatabase {
type OwnedKey: Borrow<Self::BorrowedKey>;
type KVIterator: Iterator<Item=(Self::OwnedKey, Self::OwnedValue)>;
type KeyIterator: Iterator<Item=Self::OwnedKey>;
type ValueIterator: Iterator<Item=Self::OwnedValue>;
fn iter(&self) -> Self::KVIterator;
fn iter_keys(&self) -> Self::KeyIterator;
fn iter_values(&self) -> Self::ValueIterator;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels