ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! A slot NAMES its pairing, and the two constants are what let the join be checked.

use super::{Bound, Slot};
use crate::{SlotHandle, SlotName};

/// A declaration with two elected fields, each stored in two engines — the shape the whole grammar
/// exists for.
struct SearchDocument;

/// `title` × `tantivy`.
struct TitleTantivy;
/// `title` × `hnsw` — the same field, a second engine.
struct TitleHnsw;
/// `body` × `tantivy` — the same engine, a second field.
struct BodyTantivy;

impl Slot for TitleTantivy {
  type Of = SearchDocument;

  const SLOT: &'static SlotName = SlotName::new("search_document__title__tantivy");
  const FIELD: &'static str = "title";
  const ENGINE: &'static str = "tantivy";
}

impl Slot for TitleHnsw {
  type Of = SearchDocument;

  const SLOT: &'static SlotName = SlotName::new("search_document__title__hnsw");
  const FIELD: &'static str = "title";
  const ENGINE: &'static str = "hnsw";
}

impl Slot for BodyTantivy {
  type Of = SearchDocument;

  const SLOT: &'static SlotName = SlotName::new("search_document__body__tantivy");
  const FIELD: &'static str = "body";
  const ENGINE: &'static str = "hnsw";
}

/// A third party's engine, as a graph root's `engines(…)` would bind it.
struct AppEngineHnsw;

/// The engine itself — never constructed here, only NAMED, which is all a member table does with one.
struct Hnsw;

impl Bound for AppEngineHnsw {
  type Engine = Hnsw;

  const WORD: &'static str = "hnsw";
}

/// Three slots, three names — which is what keeps three corpora apart. A pairing that dropped either
/// half of the identity would collide here.
#[test]
fn a_slot_name_is_unique_in_both_axes() {
  assert_ne!(TitleTantivy::SLOT, TitleHnsw::SLOT);
  assert_ne!(TitleTantivy::SLOT, BodyTantivy::SLOT);
}

/// The pairing is READABLE, so the join between a field's word and a root's table can be checked
/// rather than trusted.
#[test]
fn a_slot_names_the_field_and_the_engine_it_pairs() {
  assert_eq!(TitleTantivy::FIELD, "title");
  assert_eq!(TitleHnsw::FIELD, "title");
  assert_eq!(TitleTantivy::ENGINE, "tantivy");
  assert_eq!(TitleHnsw::ENGINE, "hnsw");
}

/// The BRAND takes a slot marker with no change to `SlotHandle` — `T: ?Sized` was already unbounded,
/// so the identity narrowed for free. Two slots of ONE engine type are two handle types, which is the
/// wrong-write refusal at its new grain (the compile-level half is `tests/slot_brand`).
#[test]
fn two_slots_of_one_engine_are_two_branded_handles() {
  let title: SlotHandle<(), TitleTantivy> = SlotHandle::mint(());
  let body: SlotHandle<(), BodyTantivy> = SlotHandle::mint(());

  assert_eq!(core::mem::size_of_val(&title), core::mem::size_of::<()>());
  assert_eq!(title.engine(), body.engine());
}

/// The MEMBER TABLE's fact, at the compile level: a bound word resolves to its CONCRETE type. The
/// annotation is the assertion — a table binding anything else is `E0308` here.
#[test]
fn a_bound_word_resolves_to_its_concrete_engine() {
  fn resolved(engine: <AppEngineHnsw as Bound>::Engine) -> Hnsw {
    engine
  }

  let _: fn(Hnsw) -> Hnsw = resolved;
  assert_eq!(AppEngineHnsw::WORD, "hnsw");
}

/// And the two halves AGREE — the word a field wrote and the word the root bound are one string.
/// This is the join the face round will demand through a projection; here it is stated over the two
/// constants that carry it.
#[test]
fn a_slots_engine_word_is_the_word_the_table_binds() {
  assert_eq!(TitleHnsw::ENGINE, AppEngineHnsw::WORD);
}