-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(storey): reorganize storage code again
- Loading branch information
Showing
2 changed files
with
101 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,106 @@ | ||
mod backend; | ||
mod branch; | ||
mod storage; | ||
|
||
pub use backend::{StorageBackend, StorageBackendMut}; | ||
pub use branch::StorageBranch; | ||
pub use storage::{IterableStorage, RevIterableStorage, Storage, StorageMut}; | ||
|
||
pub trait Storage { | ||
fn get(&self, key: &[u8]) -> Option<Vec<u8>>; | ||
|
||
fn has(&self, key: &[u8]) -> bool { | ||
self.get(key).is_some() | ||
} | ||
|
||
fn get_meta(&self, _key: &[u8]) -> Option<Vec<u8>>; | ||
fn has_meta(&self, key: &[u8]) -> bool { | ||
self.get_meta(key).is_some() | ||
} | ||
} | ||
|
||
pub trait StorageMut { | ||
fn set(&mut self, key: &[u8], value: &[u8]); | ||
fn remove(&mut self, key: &[u8]); | ||
|
||
fn set_meta(&mut self, _key: &[u8], _value: &[u8]); | ||
fn remove_meta(&mut self, _key: &[u8]); | ||
} | ||
|
||
pub trait IterableStorage { | ||
type KeysIterator<'a>: Iterator<Item = Vec<u8>> | ||
where | ||
Self: 'a; | ||
type ValuesIterator<'a>: Iterator<Item = Vec<u8>> | ||
where | ||
Self: 'a; | ||
type PairsIterator<'a>: Iterator<Item = (Vec<u8>, Vec<u8>)> | ||
where | ||
Self: 'a; | ||
|
||
fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a>; | ||
fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a>; | ||
fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a>; | ||
} | ||
|
||
impl<T: IterableStorage> IterableStorage for &T { | ||
type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; | ||
type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; | ||
type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; | ||
|
||
fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { | ||
(**self).keys(start, end) | ||
} | ||
|
||
fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { | ||
(**self).values(start, end) | ||
} | ||
|
||
fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { | ||
(**self).pairs(start, end) | ||
} | ||
} | ||
|
||
impl<T: IterableStorage> IterableStorage for &mut T { | ||
type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; | ||
type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; | ||
type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; | ||
|
||
fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { | ||
(**self).keys(start, end) | ||
} | ||
|
||
fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { | ||
(**self).values(start, end) | ||
} | ||
|
||
fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { | ||
(**self).pairs(start, end) | ||
} | ||
} | ||
|
||
pub trait RevIterableStorage { | ||
type RevKeysIterator<'a>: Iterator<Item = Vec<u8>> | ||
where | ||
Self: 'a; | ||
type RevValuesIterator<'a>: Iterator<Item = Vec<u8>> | ||
where | ||
Self: 'a; | ||
type RevPairsIterator<'a>: Iterator<Item = (Vec<u8>, Vec<u8>)> | ||
where | ||
Self: 'a; | ||
|
||
fn rev_keys<'a>( | ||
&'a self, | ||
start: Option<&[u8]>, | ||
end: Option<&[u8]>, | ||
) -> Self::RevKeysIterator<'a>; | ||
fn rev_values<'a>( | ||
&'a self, | ||
start: Option<&[u8]>, | ||
end: Option<&[u8]>, | ||
) -> Self::RevValuesIterator<'a>; | ||
fn rev_pairs<'a>( | ||
&'a self, | ||
start: Option<&[u8]>, | ||
end: Option<&[u8]>, | ||
) -> Self::RevPairsIterator<'a>; | ||
} |
This file was deleted.
Oops, something went wrong.