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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
//! [`LaneRouter`] — the crossing itself — and the two the framework ships.

use core::{convert::Infallible, marker::PhantomData};

use crate::{Lane, UnknownLane, lane_for, script_runs};

use super::RoutedProbe;

#[cfg(test)]
mod tests;

/// **ONE QUESTION IN, ONE PROBE PER LANE OUT** — the crossing a fanned corpus is asked through.
///
/// ```
/// use core::convert::Infallible;
///
/// use ingraph::{LaneIdent, LaneRouter, RoutedProbe};
///
/// /// Everything to one lane, whatever it says — the smallest router there is.
/// struct Always;
///
/// impl LaneRouter for Always {
///   type Question = str;
///   type Routed = String;
///   type Error = Infallible;
///
///   fn route(&self, question: &str) -> Result<Vec<RoutedProbe<String>>, Infallible> {
///     Ok(vec![RoutedProbe::new(LaneIdent::new("en"), question.to_owned())])
///   }
/// }
///
/// let routed = Always.route("hello").expect("this router cannot fail");
/// assert_eq!(routed.len(), 1);
/// assert_eq!(routed[0].probe(), "hello");
/// ```
///
/// # THE OUTPUT HAS ITS OWN TYPE, and that is what makes it a crossing
///
/// A rich question goes in and a PROBE comes out, and the two are not the same thing: a question may
/// carry filters, a floor and a caller's own vocabulary, where a probe is whatever the store on the
/// other side is asked with. Naming them separately is what lets a declaration wire a router by
/// EQUALITY — this road's question type on one side, that slot's probe type on the other — so a
/// router bolted to the wrong slot is `E0271` at the seat rather than a conversion failure at
/// runtime.
///
/// It is the reason this is not the expand step's shape. That one is an ENDOMORPHISM — questions in,
/// questions of the same type out — so it is generic over one parameter and mounts erased. This one
/// changes type, so it is a trait with three associated seats and mounts monomorphised. The two are
/// deliberately unlike and neither follows the other.
///
/// # FALLIBLE, and the infallible case says so in the type
///
/// A router that cannot fail names [`Infallible`] and the `Result` costs nothing — the same
/// discipline the crossing traits one layer over already keep. What a router that CAN fail refuses
/// with is its own type, carried whole to the road that mounted it.
///
/// # `?Sized` on the question, which is a widening and not a departure
///
/// The ruled shape wrote three plain associated types. Leaving the question unsized costs nothing
/// and buys the case that actually occurs: a textual router takes `&str` directly, where a `Sized`
/// seat would have forced every caller holding a borrow to allocate a `String` on the way in.
/// [`Routed`](Self::Routed) and [`Error`](Self::Error) stay sized, because both are returned.
///
/// # ONE FACE, and it is the blocking one
///
/// Routing is pure computation over a question and a roster: no model, no IO, nothing to await. A
/// router that eventually needs one follows the expander's dual-mode precedent at that point, and
/// nothing here has to move for it.
#[diagnostic::on_unimplemented(
  message = "`{Self}` cannot route a question into lanes",
  label = "no lane router",
  note = "a router states the question it takes, the probe type it answers in and how it refuses; \
          an infallible one names `core::convert::Infallible`",
  note = "the framework ships two — `ScriptRouter`, which cuts a text by writing system, and \
          `FanAll`, which asks every lane"
)]
pub trait LaneRouter {
  /// What this router is asked — the road's own question type, borrowed.
  type Question: ?Sized;

  /// What one lane is asked WITH — this router's own output type.
  type Routed;

  /// How routing refuses. [`Infallible`] where it cannot.
  type Error;

  /// Split `question` into one dispatch per lane it wants asked.
  ///
  /// An empty `Vec` is the EMPTY SET and not a refusal: a question with nothing in it for this
  /// corpus reaches no lane, produces no stream and is answered emptily.
  ///
  /// # Errors
  ///
  /// This router's own, carried whole.
  fn route(&self, question: &Self::Question)
  -> Result<Vec<RoutedProbe<Self::Routed>>, Self::Error>;
}

/// **ASK EVERY LANE** — the explicit fallback, and the thing a fanned corpus mounts when it has
/// nothing cleverer to say.
///
/// ```
/// use ingraph::{FanAll, Lane, LaneIdent, LaneRouter};
///
/// static CORPUS: &[Lane] = &[
///   Lane::of(LaneIdent::new("en")),
///   Lane::of(LaneIdent::new("zh")),
/// ];
///
/// let routed = FanAll::<str>::new(CORPUS).route("hello 世界").expect("cannot fail");
///
/// assert_eq!(routed.len(), 2);
/// assert_eq!(routed[0].lane(), LaneIdent::new("en"));
/// assert_eq!(routed[1].lane(), LaneIdent::new("zh"));
/// // Every lane is asked the WHOLE question — no cutting, no cleverness.
/// assert!(routed.iter().all(|probe| probe.probe() == "hello 世界"));
/// ```
///
/// # IT IS THE ANSWER TO A GUARDRAIL, which is why it is a TYPE and not a default
///
/// A fanned corpus with no router is refused at boot, because a question that reached only some of
/// its lanes would be a search quietly missing part of its corpus. *Ask all of them* is a perfectly
/// good answer to that — it costs a read per lane and lets the fold sort the results out — but it is
/// a DECISION, and the guardrail exists so that it is made rather than fallen into. Mounting this
/// says it out loud, in the declaration's own voice.
///
/// # Where it is the right answer
///
/// A corpus whose lanes are not separable from the question — short queries, code identifiers, proper
/// nouns that occur in every language's text — has nothing to route ON, and asking every lane is
/// both correct and cheap at a handful of lanes. A corpus whose lanes ARE separable should route,
/// because a read per lane is a read per lane.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FanAll<Q: ?Sized> {
  /// The roster every question is fanned across.
  lanes: &'static [Lane],
  /// The question type this router is spelled for — a marker, never a value.
  question: PhantomData<fn(&Q)>,
}

impl<Q: ?Sized> FanAll<Q> {
  /// Fan every question across `lanes`.
  #[inline]
  #[must_use]
  pub const fn new(lanes: &'static [Lane]) -> Self {
    Self {
      lanes,
      question: PhantomData,
    }
  }

  /// The roster this router fans across.
  #[inline]
  #[must_use]
  pub const fn lanes(&self) -> &'static [Lane] {
    self.lanes
  }
}

/// [`ToOwned`] rather than [`Clone`], so one implementation serves both `FanAll<str>` — where the
/// probe is a `String` — and `FanAll<MyQuestion>`, where the blanket makes it the question itself.
impl<Q> LaneRouter for FanAll<Q>
where
  Q: ToOwned + ?Sized,
{
  type Question = Q;
  type Routed = Q::Owned;
  type Error = Infallible;

  #[inline]
  fn route(&self, question: &Q) -> Result<Vec<RoutedProbe<Q::Owned>>, Infallible> {
    Ok(
      self
        .lanes
        .iter()
        .map(|lane| RoutedProbe::new(lane.key(), question.to_owned()))
        .collect(),
    )
  }
}

/// **CUT BY WRITING SYSTEM** — the shipped router, and the read side of the fan the write side
/// already runs.
///
/// ```
/// use ingraph::{Lane, LaneIdent, LaneRouter, ScriptRouter};
///
/// static CORPUS: &[Lane] = &[
///   Lane::of(LaneIdent::new("en")).accepting(&[LaneIdent::new("latn")]),
///   // One Japanese lane, fed by all THREE of the scripts a Japanese sentence is written in.
///   Lane::of(LaneIdent::new("ja"))
///     .accepting(&[LaneIdent::new("hani"), LaneIdent::new("hira"), LaneIdent::new("kana")]),
/// ];
///
/// let routed = ScriptRouter::new(CORPUS)
///   .route("日本語 report テキスト")
///   .expect("every run reaches a lane");
///
/// // TWO probes, not four: the three Japanese runs merged into the one lane they share.
/// assert_eq!(routed.len(), 2);
/// assert_eq!(routed[0].lane(), LaneIdent::new("ja"));
/// assert_eq!(routed[0].probe(), "日本語 テキスト");
/// assert_eq!(routed[1].lane(), LaneIdent::new("en"));
/// assert_eq!(routed[1].probe(), "report ");
/// ```
///
/// # THE SAME SEGMENTER, AND THE SAME GATE — which is the whole point
///
/// The write side cuts a transcript with [`script_runs`](crate::script_runs) and files each run
/// under the lane its script reaches; this cuts the question the same way and asks the lanes it
/// lands in. *What was indexed is what is asked for* is therefore true by construction rather than
/// by two implementations agreeing.
///
/// # A SCRIPT REACHES A LANE THROUGH THE DECLARED ALIASES, and no policy is invented here
///
/// Each run's script is offered to the gate as a WORD — `hani`, `latn`, `hira` — and which lane
/// answers it is the declaration's business. That is what makes this shippable at all: *this
/// corpus's Japanese is written in Han, Hiragana and Katakana, and its Chinese in Han* is a policy,
/// and a framework that guessed it would be wrong for every corpus that answered differently. A
/// Chinese-only deployment writes `zh(accepts(hani))`; a Japanese one writes the three above; one
/// holding both keys `zh` and `ja` separately and accepts what it must.
///
/// The consequence worth stating: **a corpus that declares no script aliases routes nothing**, and
/// says so by name. That is the guardrail working rather than a gap.
///
/// # A DECLARED CATCH-ALL CHANGES WHERE THE STRANGERS GO, and nothing else
///
/// The gate's own resolution is what this router spends, so a roster carrying a
/// [`catch_all`](crate::Lane::catch_all) lane sends every run whose script no lane has a home for
/// into it — a swept-in long-tail script, a run the segmenter filed under the fallback bucket, a
/// word that is not a tag at all. Nothing about the homed runs changes: a catch-all takes only what
/// nothing else does, which is the gate's law rather than this router's.
///
/// So the refusal below is what a corpus WITHOUT a catch-all gets, and it is the only shape that
/// still refuses. That is the tier-1 policy made operational: mainstream languages get lanes and
/// analyzers of their own, and the long tail is segmented correctly, routed visibly, and read by
/// whatever the catch-all's analyzer is until a story asks for better.
///
/// # SAME-LANE RUNS ARE MERGED, and that is policy rather than mechanism
///
/// Several probes for one lane are mechanically legal — [`RoutedProbe`]'s own note says so — and
/// this router declines to use that freedom: three Japanese runs become one probe, joined in the
/// order they occurred with a single space between them. Asking one lane three times would put three
/// streams into the fold for one question and let a document that matched all three outrank one that
/// matched a longer stretch of a single run, which is transcript density wearing relevance's
/// clothes.
///
/// The separator is a SPACE, inserted only where there is not one already. Every analyzer this can
/// reach treats a space as a boundary and none of them treats it as a term, so it cannot create a
/// word that was in neither run — and a run carries whatever punctuation and spacing followed it,
/// which is the segmenter's contextual rule, so `"日本語 "` followed by `"テキスト"` needs nothing
/// added between them.
///
/// # THE BLIND SPOT, stated where a chooser will read it
///
/// **A lane is only ever asked with the runs whose script routed to it**, so a term written in one
/// script inside a document written in another is unreachable from a question in the second. A
/// Chinese transcript that says `Rust` is indexed in the `zh` lane; a question that says `Rust` cuts
/// to a Latin run, routes to `en`, and asks the `zh` lane nothing at all. The document is never
/// found, and nothing anywhere reports a failure.
///
/// That is a STRUCTURAL recall loss rather than a tuning problem, and it is why
/// [`ScriptWeightedFan`] is the recommended default. This router is the EFFICIENCY option: it costs
/// one read per matched lane instead of one per declared lane, and it is the right choice for a
/// corpus whose lanes genuinely do not share vocabulary.
///
/// # Errors
///
/// [`UnknownLane`] where a run's script reaches no lane — carrying the script's word, the roster and
/// every alias, which is a sentence whose reader can add a lane, add an alias, or declare a
/// catch-all.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ScriptRouter {
  /// The roster a run's script is offered to.
  lanes: &'static [Lane],
}

impl ScriptRouter {
  /// Route by writing system, across `lanes`.
  #[inline]
  #[must_use]
  pub const fn new(lanes: &'static [Lane]) -> Self {
    Self { lanes }
  }

  /// The roster this router offers a script to.
  #[inline]
  #[must_use]
  pub const fn lanes(&self) -> &'static [Lane] {
    self.lanes
  }
}

impl LaneRouter for ScriptRouter {
  type Question = str;
  type Routed = String;
  type Error = UnknownLane;

  fn route(&self, question: &str) -> Result<Vec<RoutedProbe<String>>, UnknownLane> {
    // FIRST-APPEARANCE ORDER, which is what makes the answer deterministic without sorting: a lane
    // enters the list where its first run occurred and later runs of the same lane join it there.
    let mut merged: Vec<(&'static crate::LaneIdent, String)> = Vec::new();

    for run in script_runs(question) {
      let lane = lane_for(run.script().as_str(), self.lanes)?;
      match merged.iter_mut().find(|(key, _)| ***key == **lane.key()) {
        Some((_, text)) => {
          // The runs of one lane are not adjacent in the question, so something has to keep them
          // from fusing into a word that was in neither. A separator is inserted ONLY where there is
          // not already one: a run carries the punctuation and spacing that followed it — the
          // segmenter's contextual rule puts them there — so `"日本語 "` followed by `"テキスト"`
          // needs nothing, and adding a space anyway would leave a doubled one in every probe.
          if !text.ends_with(char::is_whitespace) && !run.text().starts_with(char::is_whitespace) {
            text.push(' ');
          }
          text.push_str(run.text());
        }
        None => merged.push((lane.key(), run.text().to_owned())),
      }
    }

    Ok(
      merged
        .into_iter()
        .map(|(lane, probe)| RoutedProbe::new(lane, probe))
        .collect(),
    )
  }
}

/// **ASK EVERY LANE, AND LEAN ON THE ONES THE QUESTION IS WRITTEN IN** — the recommended default.
///
/// ```
/// use ingraph::{Lane, LaneIdent, LaneRouter, ScriptWeightedFan};
///
/// static CORPUS: &[Lane] = &[
///   Lane::of(LaneIdent::new("en")).accepting(&[LaneIdent::new("latn")]),
///   Lane::of(LaneIdent::new("ja")).accepting(&[LaneIdent::new("hani"), LaneIdent::new("kana")]),
/// ];
///
/// let routed = ScriptWeightedFan::<str>::new(CORPUS)
///   .route("Rust guide")
///   .expect("this router cannot fail");
///
/// // EVERY lane is asked the WHOLE question — which is what finds `Rust` inside a Japanese
/// // transcript — and the lane the question is written in is the one that counts double.
/// assert_eq!(routed.len(), 2);
/// assert!(routed.iter().all(|probe| probe.probe() == "Rust guide"));
/// assert_eq!(routed[0].weight(), ScriptWeightedFan::<str>::DEFAULT_EMPHASIS);
/// assert_eq!(routed[1].weight(), 1.0);
/// ```
///
/// # WHY IT IS THE DEFAULT: the two pure strategies each lose something real
///
/// [`ScriptRouter`] asks only the lanes a question's own scripts route to, and therefore cannot find
/// a Latin term inside a CJK transcript — the mixed-content case, which is the common case in real
/// media: product names, code identifiers, place names and brands are written in Latin inside text
/// that is not. [`FanAll`] asks everything and finds it, but tells the fold nothing about which lane
/// the question actually looks like, so a corpus-wide term drowns the lane that matched.
///
/// **This takes both halves.** Every declared lane is probed with the whole question, so nothing is
/// structurally unreachable; and the lanes the question's own script runs resolve to are WEIGHTED, so
/// the fold still knows where the question came from. The recall is `FanAll`'s and the ranking is
/// `ScriptRouter`'s.
///
/// # THE WEIGHTS COME FROM THE GATE, so the emphasis obeys every rule the roster wrote
///
/// The question is cut by [`script_runs`](crate::script_runs) and each run's script word goes
/// through [`lane_for`](crate::lane_for) — the FULL six-step resolution, catch-all included. Every
/// lane some run resolves to is emphasized; every other lane keeps
/// [`RoutedProbe::UNWEIGHTED`]. Several runs may emphasize several lanes, and a question written
/// entirely in a swept-in long-tail script emphasizes the catch-all, because that is where the gate
/// sends it.
///
/// # IT NEVER REFUSES, and that is a deliberate verdict rather than an oversight
///
/// [`Error`](LaneRouter::Error) is [`Infallible`]. A run whose script the gate has no home for
/// simply emphasizes nothing — every lane is probed either way, so there is no dispatch to lose and
/// nothing to report. Refusing would mean withholding an answer this router can perfectly well give.
///
/// **Guardrail ② is the strict routers' law, not this one's**: a router that cuts a question can
/// send a probe nowhere, and that has to be caught; a router that probes every declared lane cannot.
/// [`ScriptRouter`] refuses where this one shrugs, and the difference is exactly what each is for.
///
/// # THE EMPHASIS IS UNTUNED, and this says so where a tuner will read it
///
/// [`DEFAULT_EMPHASIS`](Self::DEFAULT_EMPHASIS) is `2.0` — the matched lane counts double — chosen
/// as a defensible starting value rather than a measured one.
///
/// **The round this line once named has come and gone without turning the knob.** The cross-language
/// coverage work landed the lanes, the gate and this router; nobody measured the number, and a doc
/// promising a retune that already happened is worse than one promising none. What is owed is
/// recorded honestly instead: the number is a guess, it has never been measured, and the round that
/// will measure it is THE TUNING ROUND — the standing follow-up queue's entry (ingraph #238), which
/// is demand-gated on a real corpus rather than scheduled. That round re-measures the lexical half
/// after the C2b work, prices the fold's own effect, and turns this knob and
/// [`ArmWeights::DEFAULT_ARM_WEIGHT`](crate::ArmWeights::DEFAULT_ARM_WEIGHT) against the SAME data —
/// which is the whole reason they are one round and not two: the two numbers multiply into one
/// coefficient, so tuning either alone tunes their product by guesswork.
///
/// [`with_emphasis`](Self::with_emphasis) is the knob that round turns, and until it does a
/// deployment with its own corpus is better placed to name a number than this constant is.
///
/// # ALL THREE TIERS LAND NOW, and the third one arrives through the MINT
///
/// The emphasis is a PREFERENCE — the lane half of the product the arm weight is the other half of —
/// so the law gives it a shipped constant, a launch override and a query-time parameter, request
/// supreme. [`DEFAULT_EMPHASIS`](Self::DEFAULT_EMPHASIS) is the constant,
/// [`with_emphasis`](Self::with_emphasis) is what a deployment assembling this router calls, and the
/// third tier is a row of the tower's own `<Tower>SearchOptions` — minted where the `route(router =
/// script_weighted_fan, …)` WORD is, because that is where a macro can know which router it is
/// keying a field for.
///
/// **[`LaneRouter`] did not move, and that is the whole point of the road taken.** A per-query
/// emphasis could have arrived as a parameter on the routing trait — a surface end users extend —
/// which would have spent every third-party router's signature for a knob only the shipped routers
/// have. What happens instead is that a tower's steps are MINTED PER READ, so the router a request
/// routes through is that request's own value: the emitted run RETUNES it with
/// [`with_emphasis`](Self::with_emphasis) before the crossing and the trait never learns that
/// anything happened. Per-request configuration is free where the value is per-request already.
///
/// A recipe whose `route(…)` names a router of the DECLARING CRATE's gets no such row, and the
/// silence is honest: the macro knows the shipped roster and nothing else, so a field for a user
/// router would be a knob the emission could publish and never spend. Such a router's own tuning
/// rides its own question, which is the road [`LaneRouter::route`]'s single parameter already opens.
///
/// The contrast is [`ArmWeights`](crate::ArmWeights), which reaches its third tier through a
/// FRAMEWORK type at a framework step. Two numbers, one product, two different roads to the same
/// tier — and what they have in common is that neither of them widened a user-facing trait.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ScriptWeightedFan<Q: ?Sized> {
  /// The roster every question is fanned across, and whose lanes the emphasis lands on.
  lanes: &'static [Lane],
  /// What a lane the question is written in counts for.
  emphasis: f64,
  /// The question type this router is spelled for — a marker, never a value.
  question: PhantomData<fn(&Q)>,
}

impl<Q: ?Sized> ScriptWeightedFan<Q> {
  /// **THE SHIPPED EMPHASIS** — a lane the question is written in counts double.
  ///
  /// One source of truth, so a deployment that wants another number changes one call rather than
  /// discovering that two places disagree.
  pub const DEFAULT_EMPHASIS: f64 = 2.0;

  /// Fan every question across `lanes`, emphasizing the ones it is written in at
  /// [`DEFAULT_EMPHASIS`](Self::DEFAULT_EMPHASIS).
  #[inline]
  #[must_use]
  pub const fn new(lanes: &'static [Lane]) -> Self {
    Self {
      lanes,
      emphasis: Self::DEFAULT_EMPHASIS,
      question: PhantomData,
    }
  }

  /// The same fan, weighting a matched lane at `emphasis` instead.
  ///
  /// `1.0` makes this [`FanAll`] exactly, which is a legitimate thing to ask for and needs no second
  /// type to say.
  #[inline]
  #[must_use]
  pub const fn with_emphasis(mut self, emphasis: f64) -> Self {
    self.set_emphasis(emphasis);
    self
  }

  /// [`with_emphasis`](Self::with_emphasis), in place.
  #[inline]
  pub const fn set_emphasis(&mut self, emphasis: f64) -> &mut Self {
    self.emphasis = emphasis;
    self
  }

  /// What a lane the question is written in counts for.
  #[inline]
  #[must_use]
  pub const fn emphasis(&self) -> f64 {
    self.emphasis
  }

  /// The roster this router fans across.
  #[inline]
  #[must_use]
  pub const fn lanes(&self) -> &'static [Lane] {
    self.lanes
  }
}

/// [`AsRef<str>`] beside [`ToOwned`]: the probe is the question OWNED, and the emphasis is read off
/// the question's own TEXT — so this seat needs both halves where [`FanAll`] needed only the first.
impl<Q> LaneRouter for ScriptWeightedFan<Q>
where
  Q: ToOwned + AsRef<str> + ?Sized,
{
  type Question = Q;
  type Routed = Q::Owned;
  type Error = Infallible;

  fn route(&self, question: &Q) -> Result<Vec<RoutedProbe<Q::Owned>>, Infallible> {
    // WHICH LANES THE QUESTION IS WRITTEN IN. A run the gate has no home for contributes nothing —
    // `ok()` rather than `?`, which is the never-refuses verdict in one character.
    let emphasized: Vec<&'static Lane> = script_runs(question.as_ref())
      .filter_map(|run| lane_for(run.script().as_str(), self.lanes).ok())
      .collect();

    Ok(
      self
        .lanes
        .iter()
        .map(|lane| {
          // Pointer identity, and it is exact: both sides are borrows into `self.lanes`.
          let matched = emphasized.iter().any(|hit| core::ptr::eq(*hit, lane));
          let weight = if matched {
            self.emphasis
          } else {
            RoutedProbe::<Q::Owned>::UNWEIGHTED
          };
          RoutedProbe::new(lane.key(), question.to_owned()).with_weight(weight)
        })
        .collect(),
    )
  }
}