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::BlobLocation;
use crate::ToGraphqlOutput;

/// The address is the member a location always has, and the two facts a pure render cannot invent
/// start absent.
#[test]
fn a_bare_location_says_only_where() {
  let location = BlobLocation::new("thumbnail/clip/1.png");

  assert_eq!(location.address(), "thumbnail/clip/1.png");
  assert_eq!(location.content_type(), None);
  assert_eq!(location.size(), None);
}

/// A backend that already HOLDS the two optional facts states them, and each is independent of the
/// other — a store knowing a media type and not a length is an ordinary store.
#[test]
fn a_backend_states_what_it_already_knows() {
  let typed = BlobLocation::new("thumbnail/clip/1.png").with_content_type("image/png");
  assert_eq!(typed.content_type(), Some("image/png"));
  assert_eq!(typed.size(), None);

  let sized = BlobLocation::new("waveform/clip").with_size(4096);
  assert_eq!(sized.content_type(), None);
  assert_eq!(sized.size(), Some(4096));

  let both = BlobLocation::new("thumbnail/clip/1.png")
    .with_content_type("image/png")
    .with_size(9);
  assert_eq!(both.content_type(), Some("image/png"));
  assert_eq!(both.size(), Some(9));
}

/// The crossing is the IDENTITY row: the value is handed on by reference and never rebuilt, which is
/// what a wire face returning `<BlobLocation as ToGraphqlOutput>::Output<'_>` spends per response.
#[test]
fn the_crossing_borrows_rather_than_copies() {
  let location = BlobLocation::new("thumbnail/clip/1.png").with_size(9);
  let crossed: &BlobLocation = BlobLocation::to_graphql_output(&location);

  assert!(core::ptr::eq(crossed, &location));
}