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
//! The carrier's own shape: the ordinal is the POSITION, the list is never reordered, and the
//! correspondence with `Folded`'s subscript is the whole reason the type exists.

use super::Held;

/// The accessors, and the ordinal that is this type's whole content beyond a slice.
#[test]
fn a_set_carries_its_members_under_their_ordinals() {
  let held = Held::new(Box::new(["a", "b", "c"]));

  assert_eq!(held.len(), 3);
  assert!(!held.is_empty());
  assert_eq!(held.members(), &["a", "b", "c"]);
  assert_eq!(held.at(1), Some(&"b"));
  assert_eq!(held.at(3), None);
  assert_eq!(
    held.enumerate().collect::<Vec<_>>(),
    [(0, &"a"), (1, &"b"), (2, &"c")],
  );
  assert_eq!(&*held.into_members(), &["a", "b", "c"]);
}

/// **THE ORDINAL IS `Folded`'s SUBSCRIPT**, which is the correspondence the whole family rests on:
/// ask with a held of three, and `streams[j]` is about `at(j)`.
///
/// Written as an assertion rather than as a sentence, because a sentence cannot go red.
#[test]
fn the_ordinal_is_the_subscript_a_folded_answer_is_attributed_by() {
  use super::super::StreamBest;

  let held = Held::new(Box::new(["clip", "poster", "thumb"]));
  let folded = super::super::Folded::new(
    1.5_f32,
    Box::new([
      Some(StreamBest::new(0.9_f32, 4)),
      None,
      Some(StreamBest::new(0.6_f32, 1)),
    ]),
    "keyframe",
  );

  assert_eq!(
    held.len(),
    folded.streams().len(),
    "one sighting slot per member of the held the query was asked with",
  );
  for (ordinal, member) in held.enumerate() {
    assert_eq!(
      held.at(ordinal),
      Some(member),
      "the ordinal did not address the member it was handed with",
    );
  }
  assert!(
    folded.stream(1).is_none(),
    "the member nothing matched carries no sighting"
  );
}

/// **BOTH ITERATION FACES AGREE WITH `members`** — a borrow and a take, over one order.
#[test]
fn the_set_iterates_in_ordinal_order() {
  let held = Held::new(Box::new([10_u8, 20, 30]));

  assert_eq!(
    (&held).into_iter().copied().collect::<Vec<_>>(),
    [10, 20, 30]
  );
  assert_eq!(held.as_ref(), &[10, 20, 30]);
  assert_eq!(held.into_iter().collect::<Vec<_>>(), [10, 20, 30]);
}

/// An empty set is buildable and reads as one — the door never answers with it (a column holding
/// nothing is `Unindexed`), and the type forbids nothing it does not have to.
#[test]
fn an_empty_set_reads_as_empty() {
  let empty: Held<u8> = Held::new(Box::new([]));

  assert!(empty.is_empty());
  assert_eq!(empty.len(), 0);
  assert_eq!(empty.at(0), None);
}