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 core::{borrow::Borrow, hash::BuildHasher};
use std::collections::HashMap;

use super::ReasonName;

/// The view is exactly the string it was made from, and the strings here are the ones a charset
/// would have refused — a label is compared and printed, never quoted or made into a path, so the
/// permissiveness is the type's content rather than a gap in it.
#[test]
fn a_label_views_the_str_it_was_made_from() {
  // Through the `Deref` coercion, which is how the wire spelling reaches a `from_label`.
  let viewed: &str = ReasonName::new("oversize");
  assert_eq!(viewed, "oversize");
  assert_eq!(ReasonName::new("").len(), 0);
  assert_eq!(ReasonName::new("late frame").len(), 10);
  assert_eq!(ReasonName::new("не читается").as_ref(), "не читается");
  assert_eq!(ReasonName::new("не читается").len(), 21);
}

/// Constructible in a `const`, which is where a closed vocabulary spells its labels.
#[test]
fn a_label_is_const_constructible() {
  const OVERSIZE: &ReasonName = ReasonName::new("oversize");

  assert_eq!(OVERSIZE.as_ref(), "oversize");
}

/// [`Borrow`]'s contract, which is what makes a label countable at a tap: `Eq`, `Ord` and `Hash`
/// all forward to the inner `str`, so a label and the `str` it borrows as reach the same bucket of
/// one map. That is the shape a tap tallying refusals by reason needs before anything stores one.
#[test]
fn a_label_and_its_borrowed_str_agree() {
  let reason = ReasonName::new("oversize");
  let borrowed: &str = reason.borrow();

  let tallies = HashMap::from([("oversize", 0usize), ("unreadable", 1)]);
  assert_eq!(tallies.get(borrowed), Some(&0));
  assert_eq!(
    tallies.get(Borrow::<str>::borrow(ReasonName::new("unreadable"))),
    Some(&1)
  );

  let hasher = tallies.hasher();
  assert_eq!(hasher.hash_one(reason), hasher.hash_one(borrowed));

  assert_eq!(reason, ReasonName::new("oversize"));
  assert_eq!(
    reason.cmp(ReasonName::new("unreadable")),
    borrowed.cmp("unreadable")
  );
}