use crate::schema::entity::{Entity, EntityPart, EntityPartList};
pub trait IndexedEntityPart<const N: usize> {
type Entity: Entity;
type Part: EntityPart<Entity = Self::Entity>;
}
pub struct IndexSignifier<const N: usize>;
pub trait IndexPartList<E: Entity, II> {
type PartList: EntityPartList<Entity = E>;
}
pub type UniqueIndex<E, EPL> = Index<true, E, EPL>;
pub type SearchIndex<E, EPL> = Index<false, E, EPL>;
#[doc(hidden)]
pub struct Index<const UNIQUE: bool, E: Entity, EPL: EntityPartList<Entity = E>> {
_ghost: std::marker::PhantomData<(E, EPL)>,
}
impl<const UNIQUE: bool, E: Entity, EPL: EntityPartList<Entity = E>> Default
for Index<UNIQUE, E, EPL>
{
fn default() -> Self {
Self {
_ghost: std::marker::PhantomData,
}
}
}
impl<const UNIQUE: bool, E: Entity, EPL: EntityPartList<Entity = E>> Clone
for Index<UNIQUE, E, EPL>
{
fn clone(&self) -> Self {
Self {
_ghost: std::marker::PhantomData,
}
}
}
impl<const UNIQUE: bool, E: Entity, EPL: EntityPartList<Entity = E>> super::DatabaseItem
for Index<UNIQUE, E, EPL>
{
fn accept_item_visitor(visitor: &mut impl super::DatabaseItemVisitor) {
visitor.visit_index::<UNIQUE, E, EPL>();
}
fn build(_: super::BuildSeal) -> Self
where
Self: Sized,
{
Self {
_ghost: std::marker::PhantomData,
}
}
type Subitems = ();
}
macro_rules! entity_index {
($($is:ident : $n:tt),+) => {
impl<E: Entity $( + IndexedEntityPart<$is, Entity = E> )*, $( const $is: usize ),*> IndexPartList<E, ( $( IndexSignifier<$is> ),*, )> for E {
#[allow(unused_parens)]
type PartList = ( $( <E as IndexedEntityPart<$is>>::Part ),* );
}
}
}
entity_index!(N0:0);
entity_index!(N0:0, N1:1);
entity_index!(N0:0, N1:1, N2:2);
entity_index!(N0:0, N1:1, N2:2, N3:3);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10, N11:11);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10, N11:11, N12:12);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10, N11:11, N12:12, N13:13);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10, N11:11, N12:12, N13:13, N14:14);
entity_index!(N0:0, N1:1, N2:2, N3:3, N4:4, N5:5, N6:6, N7:7, N8:8, N9:9, N10:10, N11:11, N12:12, N13:13, N14:14, N15:15);