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
//! Which leg refused, and that each leg's error arrives as ITSELF.

use super::Refused;

/// One engine's error type.
#[derive(Debug, PartialEq, Eq)]
struct Closed;

/// Another engine's, and deliberately unconvertible into the first: two engines' errors carry no
/// bound and no relation, which is why the fan's error is a sum rather than a flattening.
#[derive(Debug, PartialEq, Eq)]
struct Corrupt(u8);

impl core::fmt::Display for Closed {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    f.write_str("the index is closed")
  }
}

impl core::fmt::Display for Corrupt {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    write!(f, "segment {} is corrupt", self.0)
  }
}

impl core::error::Error for Closed {}
impl core::error::Error for Corrupt {}

/// Each leg's error arrives AS ITSELF, at its own type — nothing is erased into a box, which is what
/// a bound on the seam would have bought and what the seam refuses to carry.
#[test]
fn each_leg_keeps_its_own_error_type() {
  let first: Refused<Closed, Corrupt> = Refused::First(Closed);
  let second: Refused<Closed, Corrupt> = Refused::Second(Corrupt(3));

  assert!(matches!(first, Refused::First(Closed)));
  assert!(matches!(second, Refused::Second(Corrupt(3))));
}

/// THREE legs by nesting, which is the arity mechanism — and the variant path is what says which leg
/// it was.
#[test]
fn a_third_leg_is_the_second_nested() {
  let third: Refused<Closed, Refused<Closed, Corrupt>> =
    Refused::Second(Refused::Second(Corrupt(9)));
  let middle: Refused<Closed, Refused<Closed, Corrupt>> = Refused::Second(Refused::First(Closed));

  assert!(matches!(
    third,
    Refused::Second(Refused::Second(Corrupt(9)))
  ));
  assert!(matches!(middle, Refused::Second(Refused::First(Closed))));
}

/// The DISPLAY names the fan only at the outermost `First`, so a nested refusal reads as one
/// sentence rather than as *the fan's first engine refused* repeated per level.
#[test]
fn the_display_names_the_fan_once() {
  let first: Refused<Closed, Corrupt> = Refused::First(Closed);
  let second: Refused<Closed, Corrupt> = Refused::Second(Corrupt(3));

  assert_eq!(
    first.to_string(),
    "the fan's first engine refused: the index is closed"
  );
  assert_eq!(second.to_string(), "segment 3 is corrupt");
}

/// The `Error` impl is CONDITIONAL, so the sum is an error exactly where its legs are — and the
/// source is the leg, so a caller walking the chain reaches the engine's own report.
#[test]
fn the_source_is_the_leg_that_refused() {
  use core::error::Error as _;

  let second: Refused<Closed, Corrupt> = Refused::Second(Corrupt(3));
  let source = second.source().expect("a fan's refusal has a source");
  assert_eq!(source.to_string(), "segment 3 is corrupt");
}

/// The one-type convenience, for the shape a field naming two words the deployment bound to ONE
/// engine has.
#[test]
fn a_fan_over_one_error_type_collapses() {
  let second: Refused<Closed, Closed> = Refused::Second(Closed);
  assert_eq!(second.into_inner(), Closed);
}