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 five gates, each measured against the feature that selects it.
//!
//! One shape per backend, and the assertion is only half of it. Each gate wraps a definition and a
//! twin stands beside it under the OPPOSITE `#[cfg]`, so the two ways a gate can be wrong are both
//! compile errors before any test runs: a gate that expanded when its feature was off would define
//! the item twice (`E0428`), and one that expanded to nothing when its feature was on would leave
//! the name unresolved (`E0425`). The `#[test]` is what gives that pair a lane to fail in.
//!
//! The gated body deliberately names something ONLY that feature's build has — the backend type an
//! emitted `Record` impl would name — because that is the property the `tt` slurp buys: the empty
//! twin discards its tokens without parsing them, so a gate over a name the build does not have is
//! silence rather than `E0433`. The public macro passes those tokens through a second slurp on the
//! way to its twin, which is the layer that could have taken the property away.
//!
//! Every invocation below is at the PUBLIC name, which is what a person writes and what the shelf
//! re-exports. That it resolves at all in a lane whose backend is absent is the first thing these
//! lanes hold: the public gate is ungated, and only the twin behind it is chosen by a feature.
//!
//! Everything here is ITEM position. The other position a gate is spent in is STATEMENT position,
//! and each macro's own example is what holds it — a doctest runs in every feature lane, so the four
//! examples are the shut gate's statement claim as well as the open gate's.

// `SQLITE` is whether the gate expanded, as the gate itself answers, and the body names
// `sqlx::Sqlite`, which exists only under that feature. A doc comment cannot ride a macro
// INVOCATION — rustdoc documents no such thing and `unused_doc_comments` says so — which is a fact
// about the gates worth knowing at the emission side too: what a gated item documents has to be
// written inside the gate.
crate::if_sqlite! {
  const SQLITE: bool = ::core::mem::size_of::<::sqlx::Sqlite>() == 0;
}

// The twin: the gate expanded to nothing, so nothing named `sqlx::Sqlite` was parsed.
#[cfg(not(feature = "sqlite"))]
const SQLITE: bool = false;

crate::if_postgres! {
  const POSTGRES: bool = ::core::mem::size_of::<::sqlx::Postgres>() == 0;
}

#[cfg(not(feature = "postgres"))]
const POSTGRES: bool = false;

crate::if_mysql! {
  const MYSQL: bool = ::core::mem::size_of::<::sqlx::MySql>() == 0;
}

#[cfg(not(feature = "mysql"))]
const MYSQL: bool = false;

crate::if_mongo! {
  const MONGO: bool = ::core::mem::size_of::<::core::marker::PhantomData<crate::Mongo>>() == 0;
}

#[cfg(not(feature = "mongo"))]
const MONGO: bool = false;

// The FAMILY gate, whose body names a type every build with sqlx has and no build without it does.
crate::gate::if_sqlx! {
  const SQLX: bool = ::core::mem::size_of::<::core::marker::PhantomData<::sqlx::Error>>() == 0;
}

#[cfg(not(feature = "sqlx"))]
const SQLX: bool = false;

/// Each gate expands exactly where its backend is compiled in.
///
/// The equality is against `cfg!` — the crate's OWN reading of its feature table, which is the
/// reading a gate claims to carry into a consumer's crate. A gate whose `#[cfg]` named the wrong
/// feature would already have failed to compile; this is what names the lane it failed in.
#[test]
fn each_gate_expands_exactly_where_its_backend_is_compiled_in() {
  assert_eq!(SQLITE, cfg!(feature = "sqlite"));
  assert_eq!(POSTGRES, cfg!(feature = "postgres"));
  assert_eq!(MYSQL, cfg!(feature = "mysql"));
  assert_eq!(MONGO, cfg!(feature = "mongo"));
  assert_eq!(SQLX, cfg!(feature = "sqlx"));
}

/// A gate reached the way an EXPANSION reaches it — through the shelf — is the same macro.
///
/// The emitter writes `#krate::__private::gate::if_<backend>!` and never the public name, so the
/// shelf path is the one that has to resolve. It is a `pub use` of a `#[macro_export]`ed
/// `macro_rules!` carried through a glob, which is the part worth pinning: a macro re-export is not
/// what a glob obviously does.
///
/// That the two are ONE macro is what makes a hand-written per-backend half and the emission beside
/// it open together. Two macros of one shape would let a build compile one half of a backend and
/// not the other.
#[test]
fn the_shelf_path_reaches_the_same_gate() {
  crate::__private::gate::if_sqlite! {
    const SHELVED: bool = true;
  }

  #[cfg(not(feature = "sqlite"))]
  const SHELVED: bool = false;

  assert_eq!(SHELVED, SQLITE);
}