|
@@ -1,8 +1,7 @@
|
|
|
-#![allow(missing_docs)]
|
|
|
-
|
|
|
-use crate::db::Connection;
|
|
|
-
|
|
|
-use super::entity::{Entity, EntityPart, EntityPartList};
|
|
|
+use crate::{
|
|
|
+ db::Connection,
|
|
|
+ schema::entity::{Entity, EntityPart, EntityPartList},
|
|
|
+};
|
|
|
|
|
|
/// Trait used to get entity part types by index, used for index schema generation.
|
|
|
pub trait IndexedEntityPart<const N: usize> {
|
|
@@ -12,17 +11,29 @@ pub trait IndexedEntityPart<const N: usize> {
|
|
|
type Part: EntityPart<Entity = Self::Entity>;
|
|
|
}
|
|
|
|
|
|
+/// Signifier used to specify which indexed part to retrieve.
|
|
|
pub struct IndexSignifier<const N: usize>;
|
|
|
|
|
|
+/// Turns a list of signifiers into an [`EntityPartList`].
|
|
|
pub trait IndexPartList<E: Entity, II> {
|
|
|
+ /// The resulting [`EntityPartList`].
|
|
|
type PartList: EntityPartList<Entity = E>;
|
|
|
}
|
|
|
|
|
|
-pub struct Index<E: Entity, EPL: EntityPartList<Entity = E>>(std::marker::PhantomData<(E, EPL)>);
|
|
|
+/// A search index across given fields. Note that since this is a unique index, it also enforces a
|
|
|
+/// uniqueness constraint across the fields.
|
|
|
+pub struct Index<E: Entity, EPL: EntityPartList<Entity = E>> {
|
|
|
+ pub(crate) conn: Connection,
|
|
|
+ _ghost: 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)
|
|
|
+ /// Construct an Index instance.
|
|
|
+ pub fn build(conn: Connection) -> Self {
|
|
|
+ Self {
|
|
|
+ conn,
|
|
|
+ _ghost: std::marker::PhantomData,
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|