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 crate::{GraphqlName, MongoName, MysqlName, PostgresName, SqliteName};

/// The view is exactly the string it was made from — the fat pointer's LENGTH crosses, so a word is
/// neither truncated nor read past its end, and a `'static` word stays `'static` through the round
/// trip. That last part is what an accessor handing back a `&'static SqliteName` rests on.
#[test]
fn a_variant_name_views_the_str_it_was_made_from() {
  const WIRE: &GraphqlName = GraphqlName::new("LOW");
  // Through the `Deref` coercion, which is how every reader of one of these takes it.
  let borrowed: &'static str = WIRE;

  assert_eq!(borrowed, "LOW");
  assert_eq!(SqliteName::new("").len(), 0);
  assert_eq!(MongoName::new("ключ").as_ref(), "ключ");
  assert_eq!(MongoName::new("ключ").len(), 8);
}

/// **The namespaces are not one type**, which is the whole content of the construction: a word that
/// came off the wire cannot be handed to a conversion that reads a stored one, and the compiler is
/// what says so rather than a convention.
///
/// A signature rather than a runtime comparison, because the claim IS a type inequality.
#[expect(
  dead_code,
  reason = "the signature is the assertion — rustc checks it without a caller"
)]
fn each_namespace_is_its_own_type<'a>(
  sqlite: &'a SqliteName,
  postgres: &'a PostgresName,
  mysql: &'a MysqlName,
  mongo: &'a MongoName,
  graphql: &'a GraphqlName,
) -> (
  &'a SqliteName,
  &'a PostgresName,
  &'a MysqlName,
  &'a MongoName,
  &'a GraphqlName,
) {
  (sqlite, postgres, mysql, mongo, graphql)
}

/// [`Borrow`]'s contract, which is the subtle half of the derives: `Eq`, `Ord` and `Hash` all
/// forward to the inner `str`, so a word and the `str` it borrows as are interchangeable as a key.
///
/// It is what counting the words one face spelled would rest on, and a `borrow` answering with
/// anything else would put the two in different buckets of one map while every signature still
/// typechecked.
#[test]
fn a_variant_name_and_its_borrowed_str_agree() {
  let word = SqliteName::new("vp09");
  let borrowed: &str = word.borrow();

  let stored = HashMap::from([("vp09", 0usize), ("Tape", 1)]);
  assert_eq!(stored.get(borrowed), Some(&0));
  assert_eq!(
    stored.get(Borrow::<str>::borrow(SqliteName::new("Tape"))),
    Some(&1)
  );

  let hasher = stored.hasher();
  assert_eq!(hasher.hash_one(word), hasher.hash_one(borrowed));

  assert_eq!(word, SqliteName::new("vp09"));
  assert_eq!(word.cmp(SqliteName::new("Tape")), borrowed.cmp("Tape"));
}