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 device's own rows, asserted where they can be: at the TYPE level.
//!
//! What the cells DO — the two mount doors, the two ignition postures, the two staging paths — is
//! asserted where it can be run, which is `ingraph/tests/stream_root.rs`: a root holding both pairs,
//! launched. What is here is the projection itself, which has no runtime side at all.
use crate::Context;

use core::convert::Infallible;

use super::{Buffered, Mount, Streaming, Worn};
use crate::{
  Async, AsyncStreamOperator, Block, Declared, Delivery, Effect, Emitter, Feed, Fin, Operator,
  StreamOperator, Unchanneled,
};

/// A BUFFERED declaration on the blocking half.
struct Buffer;

/// A STREAMING declaration on the blocking half.
struct Windows;

/// A STREAMING declaration on the awaited half — `stream, async`, the two axes multiplying.
struct AwaitedWindows;

impl Operator for Buffer {
  type Error = Infallible;
  type In = u8;
  type Out = u8;

  fn accept(
    &mut self,
    _ctx: &Context,
    _delivery: Delivery<Self::In>,
    _emitter: &mut Emitter<Self::Out>,
  ) -> Result<(), Self::Error> {
    Ok(())
  }
}

impl StreamOperator for Windows {
  type Error = Infallible;
  type In = u8;
  type Out = u8;

  fn run(
    &mut self,
    _ctx: &Context,
    _delivery: Delivery<Self::In>,
    _feed: Feed<Self::Out>,
  ) -> Result<Fin, Self::Error> {
    Ok(Fin::Spent)
  }
}

impl AsyncStreamOperator for AwaitedWindows {
  type Error = Infallible;
  type In = u8;
  type Out = u8;

  async fn run(
    &mut self,
    _ctx: &Context,
    _delivery: Delivery<Self::In>,
    _feed: Feed<Self::Out>,
  ) -> Result<Fin, Self::Error> {
    Ok(Fin::Spent)
  }
}

impl Declared for Buffer {
  const EFFECT: Effect = Effect::Pure;

  type Channels = Unchanneled;
  type Mode = Block;
  type Options = ();
  type Pair = Buffered;
  type Wires<O> = crate::Downstream<O>;
  type Attribution<O> = ();
}

impl Declared for Windows {
  const EFFECT: Effect = Effect::Pure;

  type Channels = Unchanneled;
  type Mode = Block;
  type Options = ();
  type Pair = Streaming;
  type Wires<O> = crate::Downstream<O>;
  type Attribution<O> = ();
}

impl Declared for AwaitedWindows {
  const EFFECT: Effect = Effect::Pure;

  type Channels = Unchanneled;
  type Mode = Async;
  type Options = ();
  type Pair = Streaming;
  type Wires<O> = crate::Downstream<O>;
  type Attribution<O> = ();
}

/// **THE PAIR SEAT PICKS THE CELL, AND THE MODE SEAT RIDES BESIDE IT.**
///
/// The two axes multiply rather than competing, so the cells are their product — three pair values
/// by two modes — and this is the projection an emission writes, spelled the way an emission spells
/// it.
#[test]
fn the_seats_name_the_cell_their_declaration_selected() {
  fn same<T>(_: T, _: T) {}

  same(
    Worn::<<Buffer as Declared>::Pair, <Buffer as Declared>::Mode>::default(),
    Worn::<Buffered, Block>::default(),
  );
  same(
    Worn::<<Windows as Declared>::Pair, <Windows as Declared>::Mode>::default(),
    Worn::<Streaming, Block>::default(),
  );
  same(
    Worn::<<AwaitedWindows as Declared>::Pair, <AwaitedWindows as Declared>::Mode>::default(),
    Worn::<Streaming, Async>::default(),
  );
}

/// **THE CELL CARRIES THE FACE ROW'S OWN THREE MESSAGES**, so the launch's per-node predicate is one
/// line and the obligations on `In` / `Out` / `Error` are implied by it.
#[test]
fn a_cell_projects_the_messages_of_the_pair_it_names() {
  fn takes<C, N>(_: <C as Mount<N>>::In) -> <C as Mount<N>>::Out
  where
    N: Declared,
    C: Mount<N>,
    <C as Mount<N>>::In: Into<<C as Mount<N>>::Out>,
  {
    unreachable!("the signature is the assertion")
  }
  let _ = takes::<Worn<Buffered, Block>, Buffer>;
  let _ = takes::<Worn<Streaming, Block>, Windows>;
  let _ = takes::<Worn<Streaming, Async>, AwaitedWindows>;
}

/// **SYNCNESS IS READ OFF THE CELL'S OWN PAIR**, which is what lets a root's `ALL_SYNC` fold across
/// a catalog holding both kinds. A streaming declaration has no `Driven` row for the old spelling to
/// have read one off.
#[test]
fn the_fold_reads_a_syncness_from_either_pair() {
  const {
    assert!(<Worn<Buffered, Block> as Mount<Buffer>>::SYNC);
    assert!(<Worn<Streaming, Block> as Mount<Windows>>::SYNC);
    assert!(!<Worn<Streaming, Async> as Mount<AwaitedWindows>>::SYNC);
  };
}