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
use super::{DriverKind, FanoutKind, GraphBuilder};
use crate::{
  Context, Delivery,
  operator::{Emitter, Operator},
};

/// The facts a hand-wired node states, which the mount predicate `O: Declared + Driven<O::Mode>`
/// is what makes obligatory: a node that is not emitted still says what it is, and the mode it
/// states is the one a bare declaration has.
macro_rules! declared {
  ($name:ident) => {
    impl crate::Declared for $name {
      const EFFECT: crate::Effect = crate::Effect::Pure;

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

struct Src;
declared!(Src);
impl Operator for Src {
  type In = ();
  type Out = u8;
  type Error = core::convert::Infallible;
  fn accept(
    &mut self,
    _ctx: &Context,
    _delivery: Delivery<Self::In>,
    _emitter: &mut Emitter<Self::Out>,
  ) -> Result<(), Self::Error> {
    Ok(())
  }
}

struct Mid;
declared!(Mid);
impl Operator for Mid {
  type In = u8;
  type Out = u16;
  type Error = core::convert::Infallible;
  fn accept(
    &mut self,
    _ctx: &Context,
    _delivery: Delivery<Self::In>,
    _emitter: &mut Emitter<Self::Out>,
  ) -> Result<(), Self::Error> {
    Ok(())
  }
}

#[test]
fn declares_nodes_and_edges_as_data() {
  let mut g = GraphBuilder::new();
  let s = g.source::<Src>("src", DriverKind::Thread);
  let m = g.node::<Mid>("mid", DriverKind::Async);
  let e = g.edge(&s, &m, FanoutKind::Direct);

  assert_eq!(s.id().index(), 0);
  assert_eq!(m.id().index(), 1);
  assert_eq!(e.index(), 0);

  let (nodes, edges) = g.into_parts();
  assert_eq!(nodes.len(), 2);
  assert_eq!(nodes[0].name(), "src");
  assert!(nodes[0].is_source());
  assert!(nodes[0].driver().is_thread());
  assert!(!nodes[1].is_source());
  assert_eq!(edges.len(), 1);
  assert_eq!(edges[0].from().index(), 0);
  assert_eq!(edges[0].to().index(), 1);
  assert!(edges[0].kind().is_direct());
}

#[test]
fn node_handle_is_copy() {
  let mut g = GraphBuilder::new();
  let s = g.source::<Src>("src", DriverKind::Async);
  let copy = s; // Copy — no move
  assert_eq!(s.id(), copy.id());
}