use crate::comparator::Comparator;
use crate::lending_iterator_support::{LendItem, LentItem};
pub trait Seekable<Key: ?Sized, Cmp: ?Sized + Comparator<Key>> {
fn reset(&mut self);
fn seek(&mut self, min_bound: &Key);
fn seek_before(&mut self, strict_upper_bound: &Key);
fn seek_to_first(&mut self);
fn seek_to_last(&mut self);
}
pub trait ItemToKey<Key: ?Sized>: for<'lend> LendItem<'lend> {
#[must_use]
fn item_to_key(item: LentItem<'_, Self>) -> &'_ Key;
}
#[cfg(any(feature = "lender", feature = "lending-iterator"))]
macro_rules! delegate_seekable {
($struct_name:ident.$field:tt $($extra_i_bounds:tt)*) => {
impl<Key, Cmp, I> Seekable<Key, Cmp> for $struct_name<I>
where
Key: ?Sized,
Cmp: ?Sized + Comparator<Key>,
I: Seekable<Key, Cmp> + $($extra_i_bounds)*,
{
#[inline]
fn reset(&mut self) {
self.$field.reset();
}
#[inline]
fn seek(&mut self, min_bound: &Key) {
self.$field.seek(min_bound);
}
#[inline]
fn seek_before(&mut self, strict_upper_bound: &Key) {
self.$field.seek_before(strict_upper_bound);
}
#[inline]
fn seek_to_first(&mut self) {
self.$field.seek_to_first();
}
#[inline]
fn seek_to_last(&mut self) {
self.$field.seek_to_last();
}
}
};
}
#[cfg(any(feature = "lender", feature = "lending-iterator"))]
pub(crate) use delegate_seekable;