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 smol_bytes::Utf8Bytes;

use super::AnnotatedQuestion;

/// A question with two seats a stage could fill, so the *several annotations* claim is spent rather
/// than asserted.
struct Ask {
  lang: Option<Utf8Bytes>,
  tenant: Option<u32>,
}

impl AnnotatedQuestion<Utf8Bytes> for Ask {
  fn carried(&self) -> Option<&Utf8Bytes> {
    self.lang.as_ref()
  }
}

impl AnnotatedQuestion<u32> for Ask {
  fn carried(&self) -> Option<&u32> {
    self.tenant.as_ref()
  }
}

/// THE WHOLE OF FILL-IF-ABSENT'S TEST, at the seat that answers it.
#[test]
fn a_question_says_whether_it_was_already_told() {
  let told = Ask {
    lang: Some(Utf8Bytes::from_static("ja")),
    tenant: None,
  };
  let silent = Ask {
    lang: None,
    tenant: None,
  };

  assert_eq!(
    AnnotatedQuestion::<Utf8Bytes>::carried(&told).map(Utf8Bytes::as_str),
    Some("ja"),
    "a caller's own value is what the stage reads back"
  );
  assert!(
    AnnotatedQuestion::<Utf8Bytes>::carried(&silent).is_none(),
    "an unfilled seat is the gap the stage exists to fill"
  );
}

/// TWO ANNOTATIONS ON ONE QUESTION, each read by the type that names it — the parameter's whole
/// point, which an associated type would have made unspellable.
#[test]
fn one_question_carries_as_many_annotations_as_it_has_seats() {
  let asked = Ask {
    lang: Some(Utf8Bytes::from_static("zh-Hant")),
    tenant: Some(7),
  };

  assert_eq!(
    AnnotatedQuestion::<Utf8Bytes>::carried(&asked).map(Utf8Bytes::as_str),
    Some("zh-Hant")
  );
  assert_eq!(AnnotatedQuestion::<u32>::carried(&asked), Some(&7));
}