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
//! The projections, asserted as type equations — a wrong answer is a compile error rather than a
//! failed assertion.

use super::*;

/// Two type expressions name the SAME type. Unifying `A` is the whole check.
fn same<A>(_: core::marker::PhantomData<A>, _: core::marker::PhantomData<A>) {}

/// A container this crate did not declare, standing in for the downstream collection that joins the
/// layer by writing the one impl the orphan rule always allowed it to write.
struct Roll<T>(core::marker::PhantomData<T>);

impl<T> State<Extracted<Inner>> for Roll<T> {
  type Output = T;
}

struct Tag;

/// The two rows this crate ships, and the downstream one beside them.
#[test]
fn a_container_projects_to_what_it_holds() {
  use core::marker::PhantomData as P;

  same(P::<<Vec<Tag> as State<Extracted<Inner>>>::Output>, P::<Tag>);
  same(
    P::<<Option<Tag> as State<Extracted<Inner>>>::Output>,
    P::<Tag>,
  );
  same(
    P::<<Roll<Tag> as State<Extracted<Inner>>>::Output>,
    P::<Tag>,
  );
}

/// **The state is what makes the answer per QUESTION rather than per type**, and this is the pair
/// that says so: one type, two states, two different answers.
///
/// A trait with a single `type Inner` could not express the first row and the second at once. That
/// is the whole reason the parameter is there, so it is pinned over a type where the two answers
/// actually differ — `Vec<Tag>` projects to itself under [`Identity`] and to `Tag` under the
/// extraction.
#[test]
fn one_type_answers_once_per_state() {
  use core::marker::PhantomData as P;

  same(P::<<Vec<Tag> as State<Identity>>::Output>, P::<Vec<Tag>>);
  same(P::<<Vec<Tag> as State<Extracted<Inner>>>::Output>, P::<Tag>);
}

/// The identity blanket reaches a type with no row of its own, which is what makes the layer total
/// rather than a table.
#[test]
fn every_type_answers_the_identity() {
  use core::marker::PhantomData as P;

  same(P::<<Tag as State<Identity>>::Output>, P::<Tag>);
  same(P::<<i64 as State<Identity>>::Output>, P::<i64>);
  same(
    P::<<Roll<Vec<Tag>> as State<Identity>>::Output>,
    P::<Roll<Vec<Tag>>>,
  );
}

/// Extraction is ONE level and not a fixpoint: a nested collection projects to the collection it
/// holds, which still has a projection of its own.
///
/// Pinned because "the inner type" reads like it could mean the innermost one, and a layer that
/// quietly recursed would give `Vec<Vec<Tag>>` the element `Tag` — collapsing a list of lists into a
/// list, which is exactly the reading the marker layer exists to keep distinct.
#[test]
fn extraction_reaches_one_level() {
  use core::marker::PhantomData as P;

  same(
    P::<<Vec<Vec<Tag>> as State<Extracted<Inner>>>::Output>,
    P::<Vec<Tag>>,
  );
  same(
    P::<<Option<Vec<Tag>> as State<Extracted<Inner>>>::Output>,
    P::<Vec<Tag>>,
  );
}