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 constructors every citizen's tests build values with.
//!
//! `pub(super)` rather than private, so each household's own test module reaches these rather than
//! keeping a copy of them — which is the arrangement the source crate had, read one module further
//! in.

use core::num::NonZeroI32;

use mediatime as mt;

use super::{MediaTimeRange, MediaTimestamp, Rate, Timebase};

pub(super) fn rate(num: i32, den: i32) -> Rate {
  Rate::new(mt::Rate::fps(
    num,
    NonZeroI32::new(den).expect("a denominator is never zero"),
  ))
}

pub(super) fn timebase(num: i32, den: i32) -> Timebase {
  Timebase::new(mt::Timebase::new(num, NonZeroI32::new(den).unwrap()))
}

pub(super) fn timestamp(pts: i64, num: i32, den: i32) -> MediaTimestamp {
  MediaTimestamp::new(mt::Timestamp::new(pts, timebase(num, den).get()))
}

pub(super) fn range(start: i64, end: i64, num: i32, den: i32) -> MediaTimeRange {
  MediaTimeRange::new(mt::TimeRange::new(start, end, timebase(num, den).get()))
}

/// **The two COLLECTION admissions, and the width an edge table writes for each.**
///
/// The admission itself is a bound rather than a value, so what a test can reach is its supertrait's
/// answer: an element's `SEGMENTS` are the columns one row of an edge table holds beside the key and
/// the ordinal. Pinning the numbers is what makes a segment added to either citizen visible here
/// rather than only in a rendered `CREATE TABLE`.
#[test]
fn each_admitted_element_states_the_columns_one_row_of_it_holds() {
  const fn admitted<E: crate::CollectionElement>() -> usize {
    crate::width(E::SEGMENTS)
  }

  // pts, timebase_num, timebase_den, nanos.
  assert_eq!(admitted::<MediaTimestamp>(), 4);
  // start_pts, end_pts, timebase_num, timebase_den, start_nanos, end_nanos.
  assert_eq!(admitted::<MediaTimeRange>(), 6);
}

/// **The `Vec` reading is the QUANTIFIED one for both, and it carries the element's OWN filter
/// whole** — which is the half a marker row can get wrong in silence: a quantified marker resolves
/// its inner filter through the element's `DefaultMarker`, so a citizen whose default reading drifted
/// would publish `any` over the wrong filter and still compile.
#[test]
fn a_collection_of_either_position_citizen_is_asked_through_its_own_filter() {
  fn quantified_over<T>() -> &'static str
  where
    T: crate::DefaultVecMarker,
    T::Marker: crate::ToGraphqlFilter,
  {
    core::any::type_name::<<T::Marker as crate::ToGraphqlFilter>::Filter>()
  }

  assert!(quantified_over::<MediaTimeRange>().contains("MediaTimeRangeFilter"));
  assert!(quantified_over::<MediaTimestamp>().contains("MediaTimestampFilter"));
  assert!(quantified_over::<MediaTimeRange>().contains("QuantifiedFilter"));
  assert!(quantified_over::<MediaTimestamp>().contains("QuantifiedFilter"));
}