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 super::Scored;
use crate::Score;

// Data belonging to no family: not a record's address and not an index's, just a value. Holding it
// is what living at the seam layer MEANS, and it is what a re-narrowing to one engine's key type
// would take away.
//
// NOT `Copy`, which is the other half of what it stands for: a `String`-shaped key is a key, and it
// reaches every method here except the one that hands a copy back.
#[derive(Debug, PartialEq)]
struct Anything(&'static str);

// A score shape implementing NOTHING — not `Copy`, not `PartialOrd`, not even `Debug`. Any bound
// added to `S` on the STRUCT makes this instantiation red, which is the no-bound rule stated as a
// type rather than as a sentence.
//
// Its payload is read below through `score_ref`: a shape with no capability at all is still one a
// caller can look at and take apart, which is what the borrow accessor and `into_components` are
// there for.
struct AnyShape(u32);

/// The two halves come back independently, and this hit's score is the machine-raw `f32` an engine
/// measured in: `12.5` is a distance, not a confidence, and nothing normalises it on the way
/// through.
///
/// The annotation is the other half of the assertion — the raw shape is SPELLED, because there is
/// no default left to carry it unsaid. `Scored<Anything>` is `E0107` here, which is the law: a hit
/// names its currency at every site that holds one, and `f32` is a backend's answer rather than the
/// family's.
#[test]
fn a_hit_carries_any_data_at_the_backend_s_own_scale() {
  let hit: Scored<Anything, f32> = Scored::new(Anything("caption:7"), 12.5);

  assert_eq!(hit.data_ref(), &Anything("caption:7"));
  assert_eq!(hit.score(), 12.5);
  assert_eq!(hit.into_data(), Anything("caption:7"));
}

/// The MARKED form: a hit whose SCORE TYPE states that something normalised it.
///
/// [`Score`] is the closed unit interval, so spelling it is the claim — and it is a different type
/// from the raw `f32` above, which is what makes fusing the two lists an explicit conversion rather
/// than an addition nobody notices.
#[test]
fn a_normalised_hit_declares_it_in_the_score_type() {
  let hit: Scored<Anything, Score> = Scored::new(
    Anything("caption:7"),
    Score::new(0.87).expect("0.87 is in the unit interval"),
  );

  assert_eq!(hit.data_ref(), &Anything("caption:7"));
  assert_eq!(hit.score().get(), 0.87);
}

/// The emitted accessor pair under this type's own names: the BORROW is always there, and the copy
/// sits beside it where the half is `Copy`.
///
/// Both halves are `Copy` here, so all four answer. `Anything` is not, and the tests either side of
/// this one reach it through `data_ref` alone — the gate is on the METHOD, so a shape that cannot
/// be copied loses one call rather than the type.
#[test]
fn the_borrow_is_always_there_and_the_copy_sits_beside_it() {
  let hit: Scored<u64, Score> = Scored::new(7, Score::ONE);

  assert_eq!(hit.data_ref(), &7);
  assert_eq!(hit.data(), 7);
  assert_eq!(hit.score_ref(), &Score::ONE);
  assert_eq!(hit.score(), Score::ONE);
}

/// The score parameter carries no bound at all, so a shape implementing nothing instantiates it —
/// which is what keeps a fused rank, a tuple of sub-scores or a backend's own scale spellable here.
///
/// And a score that bare is not WRITE-ONLY: `score_ref` reads it back with nothing required of it,
/// and `into_components` hands over both halves without a clone. `matched` is the same statement
/// about the TYPE — naming `Scored<D, S>` in a signature needs nothing of either parameter.
#[test]
fn a_score_shape_needs_no_capability() {
  fn matched<D, S>(hit: &Scored<D, S>) -> &D {
    hit.data_ref()
  }

  let hit = Scored::new(Anything("caption:7"), AnyShape(3));

  assert_eq!(matched(&hit), &Anything("caption:7"));
  assert_eq!(hit.score_ref().0, 3);

  let (data, score) = hit.into_components();
  assert_eq!(data, Anything("caption:7"));
  assert_eq!(score.0, 3);
}