simplify and improve db iter State init interface

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-18 22:54:16 +00:00 committed by strawberry
parent 5bce0a3a46
commit 14341bb906
2 changed files with 12 additions and 25 deletions

View file

@ -56,20 +56,30 @@ impl<'a> State<'a> {
}
pub(super) fn init_fwd(mut self, from: From<'_>) -> Self {
debug_assert!(self.init, "init must be set to make this call");
debug_assert!(!self.seek, "seek must not be set to make this call");
if let Some(key) = from {
self.inner.seek(key);
self.seek = true;
} else {
self.inner.seek_to_first();
}
self.seek = true;
self
}
pub(super) fn init_rev(mut self, from: From<'_>) -> Self {
debug_assert!(self.init, "init must be set to make this call");
debug_assert!(!self.seek, "seek must not be set to make this call");
if let Some(key) = from {
self.inner.seek_for_prev(key);
self.seek = true;
} else {
self.inner.seek_to_last();
}
self.seek = true;
self
}