refactor: error handling (#41)

This commit is contained in:
PinelliaC
2024-02-06 11:37:59 +08:00
committed by GitHub
parent fcb01d4704
commit 0b2243acf0
2 changed files with 7 additions and 3 deletions

View File

@@ -46,11 +46,15 @@ impl StorageIterator for LsmIterator {
/// `is_valid` should return false, and `next` should always return an error. /// `is_valid` should return false, and `next` should always return an error.
pub struct FusedIterator<I: StorageIterator> { pub struct FusedIterator<I: StorageIterator> {
iter: I, iter: I,
has_errored: bool,
} }
impl<I: StorageIterator> FusedIterator<I> { impl<I: StorageIterator> FusedIterator<I> {
pub fn new(iter: I) -> Self { pub fn new(iter: I) -> Self {
Self { iter } Self {
iter,
has_errored: false,
}
} }
} }

View File

@@ -106,14 +106,14 @@ impl<I: StorageIterator> StorageIterator for FusedIterator<I> {
} }
fn key(&self) -> Self::KeyType<'_> { fn key(&self) -> Self::KeyType<'_> {
if self.has_errored || !self.iter.is_valid() { if !self.is_valid() {
panic!("invalid access to the underlying iterator"); panic!("invalid access to the underlying iterator");
} }
self.iter.key() self.iter.key()
} }
fn value(&self) -> &[u8] { fn value(&self) -> &[u8] {
if self.has_errored || !self.iter.is_valid() { if !self.is_valid() {
panic!("invalid access to the underlying iterator"); panic!("invalid access to the underlying iterator");
} }
self.iter.value() self.iter.value()