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::FieldName;

/// The view is exactly the string it was made from — the fat pointer's LENGTH crosses, so a name is
/// neither truncated nor read past its end. The multi-byte case is where a lost or miscounted
/// length stops being a shorter string and starts being unsound.
#[test]
fn a_name_views_the_str_it_was_made_from() {
  // Through the `Deref` coercion, which is how every renderer on the path reads one.
  let viewed: &str = FieldName::new("timebase");
  assert_eq!(viewed, "timebase");
  assert_eq!(FieldName::new("").len(), 0);
  assert_eq!(FieldName::new("a\"b").len(), 3);
  assert_eq!(FieldName::new("ключ").as_ref(), "ключ");
  assert_eq!(FieldName::new("ключ").len(), 8);
}

/// Constructible in a `const`, which is what puts a schema's declared names where they belong.
#[test]
fn a_name_is_const_constructible() {
  const NAME: &FieldName = FieldName::new("media_id");

  assert_eq!(NAME.as_ref(), "media_id");
}

/// [`Borrow`]'s contract, which is the subtle half of the derives: `Eq`, `Ord` and `Hash` all
/// forward to the inner `str`, so a name and the `str` it borrows as are interchangeable as a key.
///
/// A `borrow` answering with anything else would put the two in different buckets of one map while
/// every signature still typechecked — so this asserts the agreement three ways, on the lookup, on
/// the hash and on the ordering.
#[test]
fn a_name_and_its_borrowed_str_agree() {
  let field = FieldName::new("timebase");
  let borrowed: &str = field.borrow();

  let columns = HashMap::from([("timebase", 0usize), ("bitrate", 1)]);
  assert_eq!(columns.get(borrowed), Some(&0));
  assert_eq!(
    columns.get(Borrow::<str>::borrow(FieldName::new("bitrate"))),
    Some(&1)
  );

  let hasher = columns.hasher();
  assert_eq!(hasher.hash_one(field), hasher.hash_one(borrowed));

  assert_eq!(field, FieldName::new("timebase"));
  assert_eq!(
    field.cmp(FieldName::new("bitrate")),
    borrowed.cmp("bitrate")
  );
}