use crate::{
db::{
data::{DataKey, RawRow, StorageKey},
index::{IndexStore, RawIndexEntry, RawIndexKey},
},
error::InternalError,
model::index::IndexModel,
traits::{EntityKind, EntityValue},
types::EntityTag,
};
use std::{cell::RefCell, ops::Bound, thread::LocalKey};
pub(in crate::db) trait SealedPrimaryRowReader<E: EntityKind + EntityValue> {}
pub(in crate::db) trait SealedStructuralPrimaryRowReader {}
pub(in crate::db) trait SealedIndexEntryReader<E: EntityKind + EntityValue> {}
pub(in crate::db) trait SealedStructuralIndexEntryReader {}
pub(in crate::db) trait PrimaryRowReader<E: EntityKind + EntityValue>:
SealedPrimaryRowReader<E>
{
fn read_primary_row(&self, key: &DataKey) -> Result<Option<RawRow>, InternalError>;
}
pub(in crate::db) trait StructuralPrimaryRowReader:
SealedStructuralPrimaryRowReader
{
fn read_primary_row_structural(&self, key: &DataKey) -> Result<Option<RawRow>, InternalError>;
}
pub(in crate::db) trait IndexEntryReader<E: EntityKind + EntityValue>:
SealedIndexEntryReader<E>
{
fn read_index_entry(
&self,
store: &'static LocalKey<RefCell<IndexStore>>,
key: &RawIndexKey,
) -> Result<Option<RawIndexEntry>, InternalError>;
fn read_index_keys_in_raw_range(
&self,
store: &'static LocalKey<RefCell<IndexStore>>,
index: &IndexModel,
bounds: (&Bound<RawIndexKey>, &Bound<RawIndexKey>),
limit: usize,
) -> Result<Vec<StorageKey>, InternalError>;
}
pub(in crate::db) trait StructuralIndexEntryReader:
SealedStructuralIndexEntryReader
{
fn read_index_entry_structural(
&self,
store: &'static LocalKey<RefCell<IndexStore>>,
key: &RawIndexKey,
) -> Result<Option<RawIndexEntry>, InternalError>;
fn read_index_keys_in_raw_range_structural(
&self,
entity_path: &'static str,
entity_tag: EntityTag,
store: &'static LocalKey<RefCell<IndexStore>>,
index: &IndexModel,
bounds: (&Bound<RawIndexKey>, &Bound<RawIndexKey>),
limit: usize,
) -> Result<Vec<StorageKey>, InternalError>;
}
impl<E> StructuralIndexEntryReader for dyn IndexEntryReader<E> + '_
where
E: EntityKind + EntityValue,
{
fn read_index_entry_structural(
&self,
store: &'static LocalKey<RefCell<IndexStore>>,
key: &RawIndexKey,
) -> Result<Option<RawIndexEntry>, InternalError> {
self.read_index_entry(store, key)
}
fn read_index_keys_in_raw_range_structural(
&self,
_entity_path: &'static str,
_entity_tag: EntityTag,
store: &'static LocalKey<RefCell<IndexStore>>,
index: &IndexModel,
bounds: (&Bound<RawIndexKey>, &Bound<RawIndexKey>),
limit: usize,
) -> Result<Vec<StorageKey>, InternalError> {
self.read_index_keys_in_raw_range(store, index, bounds, limit)
}
}
impl<E> StructuralPrimaryRowReader for dyn PrimaryRowReader<E> + '_
where
E: EntityKind + EntityValue,
{
fn read_primary_row_structural(&self, key: &DataKey) -> Result<Option<RawRow>, InternalError> {
self.read_primary_row(key)
}
}
impl<E> SealedStructuralPrimaryRowReader for dyn PrimaryRowReader<E> + '_ where
E: EntityKind + EntityValue
{
}
impl<E> SealedStructuralIndexEntryReader for dyn IndexEntryReader<E> + '_ where
E: EntityKind + EntityValue
{
}