Skip to content

Commit

Permalink
refactor: error handling (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
PinelliaC authored Feb 6, 2024
1 parent fcb01d4 commit 0b2243a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion mini-lsm-starter/src/lsm_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ impl StorageIterator for LsmIterator {
/// `is_valid` should return false, and `next` should always return an error.
pub struct FusedIterator<I: StorageIterator> {
iter: I,
has_errored: bool,
}

impl<I: StorageIterator> FusedIterator<I> {
pub fn new(iter: I) -> Self {
Self { iter }
Self {
iter,
has_errored: false,
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions mini-lsm/src/lsm_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ impl<I: StorageIterator> StorageIterator for FusedIterator<I> {
}

fn key(&self) -> Self::KeyType<'_> {
if self.has_errored || !self.iter.is_valid() {
if !self.is_valid() {
panic!("invalid access to the underlying iterator");
}
self.iter.key()
}

fn value(&self) -> &[u8] {
if self.has_errored || !self.iter.is_valid() {
if !self.is_valid() {
panic!("invalid access to the underlying iterator");
}
self.iter.value()
Expand Down

0 comments on commit 0b2243a

Please sign in to comment.