ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! The ENGLISH PLURAL at expansion time — the word a list face is named from when a declaration
//! wrote none.
//!
//! One entity is `Reel` and its page is `reels`, and nothing in `heck` knows that: casing is a
//! mechanical transform over the characters a name already has, and a plural is a fact about the
//! LANGUAGE. So the word comes from here, and the casing helpers keep their own job — this module
//! never changes a letter's case, and no caller of it may pluralise by hand.
//!
//! # The dependency lives on the EXPANSION side, and that is the whole of its reach
//!
//! `ingraph-codegen` is reached only through `ingraph-derive`, which is a proc-macro crate — so this
//! crate and everything it names are built for the HOST and linked into the compiler's macro tier,
//! never into a consumer's binary. A declaring crate pays for the pluraliser once at build time and
//! ships not one byte of it. The dep tree is what says so rather than this sentence:
//! `cargo tree -p ingraph -e normal` reaches `pluralizer` only under the `(proc-macro)` node, and a
//! build with `default-features = false` — the derive off — has no path to it at all.
//!
//! # WHICH crate, and the measurement that chose it
//!
//! Three carry an English plural: `pluralizer` 0.5.0, `cruet` 1.0.0 (the maintained Inflector fork)
//! and `inflection-rs` 0.2.2. `inflections` is in the family by name only — it is a CASING library
//! with no plural in it at all, which is also why taking it would have meant a second casing
//! authority beside `heck`.
//!
//! All three were run over this repository's own entity names and over a wider English corpus. The
//! two failure modes are not equally bad, and that is what decided it:
//!
//! | | `pluralizer` 0.5 | `cruet` 1.0 | `inflection-rs` 0.2 |
//! |---|---|---|---|
//! | `Splice` (a corpus record) | `Splices` | **`Splice`** | **`Splice`** |
//! | `Slice` | `Slices` | **`Slice`** | `Slices` |
//! | `Child` / `Life` / `Knife` | `Children` / `Lives` / `Knives` | **`Childs` / `Lifes` / `Knifes`** | `Children` / `Lives` / `Knives` |
//! | `Person` / `Datum` / `Analysis` | `People` / `Data` / `Analyses` | **`Persons` / `Datums`** / `Analyses` | `People` / `Data` / `Analyses` |
//! | `Media` / `Audio` (mass nouns) | `Media` / `Audio` | **`Medias` / `Audios`** | `Media` / `Audios` |
//! | last release | 2025-01-17 | 2026-04-03 | 2025-05-16 |
//! | dependencies | `once_cell`, `regex` | `regex` | `deunicode`, `lazy_static`, `regex` |
//! | licence | MIT OR Apache-2.0 | BSD-2-Clause | MIT |
//!
//! `cruet` is the more recently released of the two, and it is the one this framework cannot use: a
//! wrong plural that DIFFERS from the singular is silent — `childs` reaches a schema, no rule can
//! see that it is wrong, and a client reads it forever. A word the pluraliser cannot inflect comes
//! back UNCHANGED, which is loud: it is exactly the degenerate case the list face refuses by name,
//! and the declaration answers it with `graphql(plural = "…")`. So the crate whose failures are the
//! loud kind is the one that fits a design built on refusing silence — and `pluralizer` also has the
//! better irregulars by a wide margin, which is the same argument one level down.
//!
//! Version `0.5` and no patch floor, per the deps law: `0.minor` IS a `0.x` crate's compatibility
//! axis.
//!
//! # What this answers, and what it deliberately does not
//!
//! * **Multi-word names pluralise their LAST word**, and by construction rather than by a split
//!   written here: the rules are anchored at the END of the word, so `MediaAsset` → `MediaAssets`
//!   and `VideoChild` → `VideoChildren` fall out of asking the whole name. Nothing tokenises a
//!   camel-cased name, so no second casing authority appears.
//! * **Case is not this layer's business.** A few irregulars come back with a lower-case initial
//!   (`Foot` → `feet`, `Man` → `men`) because the crate's table stores the replacement in lower
//!   case. That never reaches a schema: a root field is spelled with a lower initial anyway, so
//!   `feet` is the field name either way. Measured, and pinned in this module's tests.
//! * **A degenerate answer is not refused here.** `Media` → `Media`, `Series` → `Series`,
//!   `Dimensions` → `Dimensions`: the word has no distinct plural, or already is one. This function
//!   reports what English gave it; whether that is usable is the CALLER's question, asked where the
//!   word is spent — see [`RecordModel::degenerate_plural`](crate::model::RecordModel::degenerate_plural).

/// The count that asks for the plural. `pluralizer`'s entry point inflects for a COUNT, one being
/// the singular and anything else the plural, so the plural is asked for by naming a number that is
/// not one rather than by a second function.
const PLURAL: isize = 2;

/// The English plural of one word, as the list face's default name is built from.
///
/// The word is answered VERBATIM where the language has no distinct plural for it — see the module
/// note, which carries what that means for the caller and where the refusal lives.
///
/// ```
/// assert_eq!(ingraph_codegen::plural::of("Reel"), "Reels");
/// assert_eq!(ingraph_codegen::plural::of("VideoTrack"), "VideoTracks");
/// assert_eq!(ingraph_codegen::plural::of("Analysis"), "Analyses");
/// assert_eq!(ingraph_codegen::plural::of("Media"), "Media");
/// ```
#[must_use]
pub fn of(word: &str) -> String {
  // `false` is the INCLUSIVE flag: with it the crate answers "2 reels", counting the thing it
  // inflected. A field name carries no count.
  pluralizer::pluralize(word, PLURAL, false)
}

#[cfg(test)]
mod tests;