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 CURRENCY BOUND** — what a hit's `score` row demands of the engine's own score type, and the
//! one place the crossing is spelled for it.
//!
//! # The seat was `OutputType` and the widths beside it had already moved
//!
//! Every DECLARED column crosses through [`ToGraphqlOutput`](super::ToGraphqlOutput), so the SCALAR
//! SUITE names each one's width in the schema: an `f32` column publishes `f32` and an `f64` column
//! `f64`. A score did not travel that map. It was bound `OutputType` and reached async-graphql's own
//! rows directly, which publish both float widths as `Float` — so the one row on a hit that IS a
//! measurement was the one row that did not say which measurement it was, beside columns that did.
//!
//! Routing `S` through the crossing is the whole of the correction. The DOCTRINE is untouched:
//! **scores compare INSIDE one result list and nowhere else**, each engine measuring in its own unit,
//! at its own scale, in its own direction. What moves is the WIDTH a client reads the number at —
//! `score: f32!` where the engine's currency is an `f32` — which is a fact about precision and not
//! about comparability, and which sharpens the doctrine rather than softening it: two lists whose
//! scores a client must not compare are now two lists whose scores it cannot even mistake for one
//! type.
//!
//! # It is a TRAIT rather than a where-clause repeated ten times
//!
//! `Output<'a>` is a GAT carrying `where Self: 'a`, so the demand a backend makes of a crossed form
//! is higher-ranked — `for<'a> <S as ToGraphqlOutput>::Output<'a>: OutputType` — and that clause is
//! well formed only where `S: 'static` puts `S: 'a` within reach for every lifetime. Ten impls (five
//! types, a [`TypeName`](async_graphql::TypeName) and an `#[Object]` apiece) would each have carried
//! both halves, and a clause written ten times is a clause nine of which can drift.
//!
//! So the pair is stated ONCE, as the blanket impl below, and every hit type asks for [`WireScore`].
//! The GAT's own bound is where the backend's demand lands, which is the law
//! [`output`](super::output) states from the other side: the MAP's seat is bare because a form is one
//! fact every binding shares, and each backend asks for what it needs at its own consumption point —
//! and this module IS that point, gated on the binding like the two faces it serves.

use async_graphql::OutputType;

use super::ToGraphqlOutput;

#[cfg(test)]
mod tests;

/// A SCORE that can be rendered: it crosses through [`ToGraphqlOutput`], and the form it crosses to
/// is one async-graphql can put on a wire.
///
/// # Blanket, and there is no other implementer
///
/// The one impl is over every `T` satisfying the pair, so joining is not an act: a currency with a
/// crossing row already has this, and a currency without one is refused at the face that names it
/// with `ToGraphqlOutput` in the note rather than with a trait whose name says nothing about what is
/// missing. That is why the trait has no `#[doc(hidden)]` seal and no sealing supertrait — sealing
/// buys nothing over a blanket impl nobody can write around, and it would cost the honest error.
///
/// # `Send + Sync + 'static` are three separate obligations, and each is spent
///
/// `Send + Sync` because a hit type holding the score has to be one — `OutputType` demands both, and
/// `Match<N, S>` is an `OutputType`. `'static` because the higher-ranked bound below is well formed
/// only where `S: 'a` holds for every `'a`, which `S: 'static` is the one way to supply. It costs a
/// declaration nothing that was not already true: an engine's `Score` is a number.
///
/// # Examples
///
/// A currency with a crossing row already satisfies it, at whichever width it measures in:
///
/// ```
/// # #[cfg(feature = "async-graphql")]
/// # fn main() {
/// fn scored<S: ingraph::WireScore>() {}
///
/// scored::<f32>();
/// scored::<f64>();
/// scored::<u64>();
/// # }
/// # #[cfg(not(feature = "async-graphql"))]
/// # fn main() {}
/// ```
///
/// A currency with none is refused where the seat is named, and the note names the CROSSING — the
/// row that is missing — rather than this trait, which nobody implements by hand:
///
/// ```compile_fail
/// struct Unpriced;
///
/// fn scored<S: ingraph::WireScore>() {}
///
/// fn main() {
///   scored::<Unpriced>();
/// }
/// ```
pub trait WireScore: Send + Sync + 'static {
  /// The form this score crosses into, and it is `OutputType` — the BACKEND's demand, made where the
  /// backend spends the form.
  type Wire<'a>: OutputType
  where
    Self: 'a;

  /// This score, in that form.
  fn wire_score(&self) -> Self::Wire<'_>;
}

impl<T> WireScore for T
where
  T: ToGraphqlOutput + Send + Sync + 'static,
  for<'a> <T as ToGraphqlOutput>::Output<'a>: OutputType,
{
  type Wire<'a>
    = <T as ToGraphqlOutput>::Output<'a>
  where
    Self: 'a;

  #[inline]
  fn wire_score(&self) -> Self::Wire<'_> {
    <T as ToGraphqlOutput>::to_graphql_output(self)
  }
}