use crate::{
db::{cursor::IndexScanContinuationInput, direction::Direction, index::RawIndexStoreKey},
error::InternalError,
};
use std::ops::Bound;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(in crate::db) struct ContinuationKeyRef<'a> {
raw_key: &'a RawIndexStoreKey,
}
impl<'a> ContinuationKeyRef<'a> {
#[must_use]
pub(in crate::db) const fn scan(raw_key: &'a RawIndexStoreKey) -> Self {
Self { raw_key }
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(in crate::db) struct ContinuationRuntime<'a> {
scan: IndexScanContinuationInput<'a>,
}
impl<'a> ContinuationRuntime<'a> {
#[must_use]
pub(in crate::db) const fn new(scan: IndexScanContinuationInput<'a>) -> Self {
Self { scan }
}
pub(in crate::db) fn scan_bounds(
&self,
bounds: (&Bound<RawIndexStoreKey>, &Bound<RawIndexStoreKey>),
) -> Result<(Bound<RawIndexStoreKey>, Bound<RawIndexStoreKey>), InternalError> {
self.scan.resume_bounds(bounds)
}
pub(in crate::db) fn accept_key(
&self,
key: ContinuationKeyRef<'_>,
) -> Result<(), InternalError> {
self.scan.validate_candidate_advancement(key.raw_key)
}
#[must_use]
pub(in crate::db) const fn direction(&self) -> Direction {
self.scan.direction()
}
}