|
@@ -0,0 +1,58 @@
|
|
|
+#![allow(missing_docs)]
|
|
|
+
|
|
|
+use crate::db::Connection;
|
|
|
+
|
|
|
+use super::entity::{Entity, EntityPart, EntityPartList};
|
|
|
+
|
|
|
+/// Trait used to get entity part types by index, used for index schema generation.
|
|
|
+pub trait IndexedEntityPart<const N: usize> {
|
|
|
+ /// What entity is this part for?
|
|
|
+ type Entity: Entity;
|
|
|
+ /// The actual target part
|
|
|
+ type Part: EntityPart<Entity = Self::Entity>;
|
|
|
+}
|
|
|
+
|
|
|
+pub struct IndexSignifier<const N: usize>;
|
|
|
+
|
|
|
+pub trait IndexPartList<E: Entity, II> {
|
|
|
+ type PartList: EntityPartList<Entity = E>;
|
|
|
+}
|
|
|
+
|
|
|
+pub struct Index<E: Entity, EPL: EntityPartList<Entity = E>>(std::marker::PhantomData<(E, EPL)>);
|
|
|
+
|
|
|
+impl<E: Entity, EPL: EntityPartList<Entity = E>> Index<E, EPL> {
|
|
|
+ pub fn build(_conn: Connection) -> Self {
|
|
|
+ Self(std::marker::PhantomData)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl<E: Entity, EPL: EntityPartList<Entity = E>> super::DatabaseItem for Index<E, EPL> {
|
|
|
+ fn accept_item_visitor(visitor: &mut impl super::DatabaseItemVisitor) {
|
|
|
+ visitor.visit_index::<E, EPL>();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+macro_rules! entity_index {
|
|
|
+ ($($is:ident : $n:tt),+) => {
|
|
|
+ impl<E: Entity $( + IndexedEntityPart<$is, Entity = E> )*, $( const $is: usize ),*> IndexPartList<E, ( $( IndexSignifier<$is> ),*, )> for E {
|
|
|
+ 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);
|