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::{EqSeen, HashSeen, Seen};

/// A key that hashes and one that does not, sharing a shape — which is what makes the two rows of
/// the mechanism table comparable rather than two fixtures.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Hashable(&'static str, i64);

/// A key whose id is a FLOAT, so [`Hash`] is unavailable to it and `dedup(eq)` is the only word it
/// can be declared with. It is the escape stated as a type.
#[derive(Debug, Clone, PartialEq)]
struct Unhashable(f64);

/// Both memberships answer the same question: first sighting admitted, every repeat refused.
#[test]
fn both_mechanisms_admit_once_and_refuse_the_repeat() {
  fn walk<K: Clone, D: Seen<K>>(keys: &[K]) -> Vec<bool> {
    let mut seen = D::empty();
    keys.iter().map(|key| seen.admit(key)).collect()
  }

  let keys = [
    Hashable("m1", 1),
    Hashable("m1", 2),
    Hashable("m1", 1),
    Hashable("m2", 1),
    Hashable("m1", 2),
  ];

  let admitted = vec![true, true, false, true, false];
  assert_eq!(walk::<_, HashSeen<_>>(&keys), admitted);
  assert_eq!(walk::<_, EqSeen<_>>(&keys), admitted);
}

/// The escape actually escapes: a key with no [`Hash`] is deduped by the equality mechanism, and
/// the same type would not compile against [`HashSeen`].
#[test]
fn the_equality_mechanism_takes_a_key_that_cannot_hash() {
  let mut seen = EqSeen::empty();

  assert!(seen.admit(&Unhashable(0.5)));
  assert!(seen.admit(&Unhashable(0.25)));
  assert!(!seen.admit(&Unhashable(0.5)));
}

/// A membership starts EMPTY, which is what makes each retrieve independent of the last: there is
/// no cross-call seen-set, and v1 has no cursor for one to ride.
#[test]
fn a_membership_starts_empty() {
  let mut hashed: HashSeen<Hashable> = Seen::empty();
  let mut listed: EqSeen<Hashable> = Seen::empty();

  assert!(hashed.admit(&Hashable("m1", 1)));
  assert!(listed.admit(&Hashable("m1", 1)));
}