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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
//! THE ORIGIN LAYER: what puts the first message on a graph's wires, and the three seats its life
//! is lived through.
//!
//! An [`Operator`](crate::Operator) is written around an item somebody else produced. A SOURCE is
//! the party at the head of that chain — a directory walk, a socket loop, a watcher over a
//! filesystem, an upload arriving — and the difference is not the shape of its body but the shape
//! of its LIFE: an operator is called once per item and returns, and a source is started once and
//! runs until it is finished or told to stop.
//!
//! So [`run`](Source::run) is the whole of it, and everything the framework has to say to a source
//! or hear from one crosses one of three seats it is handed:
//!
//! | seat | direction | what it carries |
//! |---|---|---|
//! | [`Context`] | world ↔ source | this origin's own WINDOW — its wind-down line, its name, the deployment's resources |
//! | [`Feed<Y>`] | source → graph | the items this origin produces, one at a time, with backpressure |
//! | [`Control<C>`] | app → source | typed commands, for an origin whose subject changes while it runs |
//!
//! # THE CONSTRUCTION WINDOW IS [`Resources`], and the runtime one is [`Context`]
//!
//! [`build`](Source::build) runs in the CREATE WALK, before this origin has a mount — so there is no
//! wind-down line to hand it and no node name minted yet, and the window it takes is the map of what
//! the walk has already built. [`run`](Source::run) runs in a MOUNTED body, where all three of those
//! facts exist, and takes the [`Context`] that carries them.
//!
//! That is the framework's one rule and not this face's own: every construction door in the crate —
//! [`AsyncResource::build`](crate::AsyncResource::build),
//! [`AsyncConstructor::with_options`](crate::AsyncConstructor) and these two — takes `&Resources`,
//! and every running body takes a [`Context`]. A construction door signing the runtime window would
//! be promising a wind-down line the stage it runs in has not got.
//!
//! The window LEADS, at this face as at every other, and it is taken BY VALUE for `self`'s own
//! reason: an origin is started once, so the window it was built with is the window it lives in.
//! [`ShutdownSignal`] is what [`shutdown`](Context::shutdown) hands back — *wind down*, the one
//! thing the framework ever says — and it wore this seat alone until the window arrived.
//!
//! and [`Fin`] is what a run that ENDED answers with — which of the two endings this line reached.
//! A run that DIED answers its own [`Error`](Source::Error) instead, the two arriving as the two
//! arms of one `Result`: a life has two ordinary endings and one way of not ending at all, and the
//! `Result` is exactly that shape rather than a third arm bolted onto a closed axis.
//!
//! # The seats name no transport
//!
//! All three are backed by the same channel crate the rest of the drive layer is, and none of them
//! says so in a signature. That is [`Inbox::drain`](crate::Inbox)'s law one layer up: which channel
//! crate carries this framework is an implementation choice, and a public type naming it would make
//! the choice part of the API — a source author would be writing against `flume` and could not be
//! moved off it.
//!
//! What IS in the API is the two standard faces: [`Feed`] wears [`futures_sink::Sink`] and
//! [`Control`] wears [`futures_core::Stream`], so a body written with somebody else's combinators
//! can spend either seat without this crate shipping combinators of its own.
//!
//! # TWO FACES, and an author writes exactly one
//!
//! [`Source`] is the BLOCKING face and [`AsyncSource`] the awaited one, per the dual-mode law the
//! [`Operator`](crate::Operator) pair states: the bare name is the blocking body and the `Async`
//! prefix is the one whose answer has to be awaited. A scanning walk and a blocking socket loop are
//! the first face; an origin whose life is a stream of futures is the second.
//!
//! Both take the SAME three seats with the same types, and both answer the same
//! `Result<Fin, Self::Error>`. The only difference is whether a verb mints a future — `run` on both
//! faces, and `build` on the awaited one — which is what a driver has to be able to tell from the
//! type, and what a single trait carrying two verbs would hide.
//!
//! # THE MUTATION SEAT, and the two nothings
//!
//! Not every origin is controllable, and the one that is says so in its type:
//! [`Source::Mutation`] names a [`MutationNode`] — the node whose fields ARE this source's command
//! vocabulary — and an origin nobody controls writes `()`.
//!
//! `()` is the SEAT-LEVEL nothing and [`Noop`](crate::Noop) is the WIRE-LEVEL one, and they are not
//! interchangeable. See [`MutationNode`]'s own note, which is where the law is written.
//!
//! # ONE command face per source
//!
//! A source mounts AT MOST ONE mutation node. The seat is a single type rather than a list because
//! a second node buys nothing a wider first one does not: the wire face is per-FIELD, so N nodes and
//! one node with N fields are the same schema and the same author experience — and the multi-mount
//! machinery (a source-level command sum, a declaration order that becomes a tuple order, a two-level
//! match in every `run`) is real. The tuple spelling is left free on purpose, so the day two
//! vocabularies truly diverge the widening is additive and breaks nothing.
use ;
use Arc;
// Imported for METHOD RESOLUTION — the two faces below are implemented by delegating to the
// transport's own, and a trait's methods are callable only where the trait is in scope. `Sink` is
// unambiguous HERE and only here: this crate's own [`Sink`](crate::Sink) is the routing capability
// an out-edge implements, and nothing in this module names it.
use Stream;
use Sink;
use crate::;
/// ONE EXCHANGE: what a single field of a mutation node IS — a request in, a response out, and a
/// failure that may come back instead.
///
/// A mutation node's fields ARE its vocabulary, one field per thing an app can say, and this is what
/// a field's TYPE has to answer. Everything else about that field — which handler runs it, what the
/// wire calls it, what a failure renders as — is the DECLARATION's business and is written in words
/// beside the field rather than baked into its type.
///
/// # The TUPLE is the short spelling, and it is a real one
///
/// `(Request, Response)` implements this trait, so an exchange with nothing else to say is written
/// as the pair it is:
///
/// ```
/// use ingraph::Mutation;
///
/// struct AddWatch { root: String }
/// struct AddResponse { id: u64 }
///
/// // Written as a pair, read as an exchange.
/// fn takes<M: Mutation>() {}
/// takes::<(AddWatch, AddResponse)>();
///
/// // And a response of `()` is an exchange that answers only *it worked*.
/// takes::<(AddWatch, ())>();
/// ```
///
/// An exchange that needs to say more implements the trait on a type of its own. Both are ordinary:
/// the seat is `M: Mutation` and never a tuple, so nothing in this framework can tell which spelling
/// a field used.
///
/// # `type Error` is the TRAIT world's floor, and the declaration's `error(…)` word is the other
///
/// The tuple's error is `Box<dyn Error + Send + Sync + 'static>` — deliberately the widest thing
/// that is still an error, because a pair written by hand has said nothing about how it fails and a
/// floor that demanded more would make the short spelling unusable.
///
/// **It is not what `#[ingraph::mutation]` emits against.** A declared exchange's failure is decided
/// by the `error(…)` word inside its `handler(…)` block — a named type, a canned message, or
/// nothing at all — and those three are the three handler signatures the macro's own doc tabulates.
/// The two worlds do not mix: this seat serves the party that spends a `Mutation` DIRECTLY (a
/// hand-wired call, a test, a caller that never wrote a declaration), and the word serves the
/// emission. A single type can be in both, and neither reads the other's answer.
///
/// # There is no `Error: Coded` bound, and that is a ruling rather than an omission
///
/// An error code is a fact the DECLARATION states (`error(…, code = "…")`), not a capability its
/// type must have. Binding a `Coded` supertrait here would make every hand-written exchange owe a
/// code before it could exist, and would make a code impossible to write for a foreign error type
/// the author does not own — which is most of the interesting ones.
/// THE PAIR: an exchange with nothing to say beyond its two types.
///
/// The error is the boxed floor — the trait world's most tolerant answer, per the type's own note —
/// so that writing `(Request, Response)` costs an author no decision they had not already made.
/// THE COMMAND FACE of a source: the node whose fields are the vocabulary an app can say to it.
///
/// A thin seat, and deliberately: what a mutation node IS — its fields (each of them one
/// [`Mutation`]), their handlers, the errors each declares — is the mutation declaration's business,
/// and what the SOURCE layer needs of it is one thing only, which is the type a [`Control`] line
/// carries.
///
/// # The two nothings, and why `()` sits here
///
/// | spelling | what it is | where it belongs |
/// |---|---|---|
/// | `()` | the SEAT-LEVEL nothing — this source has no command face at all | [`Source::Mutation`] |
/// | [`Noop`](crate::Noop) | the WIRE-LEVEL nothing — a published position whose honest content is none | a schema row that must render as something |
///
/// They are not two spellings of one fact. `()` is ABSENCE at compile time: the seat is filled by
/// the type that carries no information, nothing is emitted for it, and the control arm of `run` is
/// provably dead. `Noop` is a type a schema HOLDS — it exists because an emitted row has to render,
/// and its own note says so. Putting `Noop` in this seat would make one word mean both, and a source
/// that mounts nothing would publish a command face saying nothing.
///
/// # The arm nothing can reach
///
/// `()`'s command type is [`Infallible`](core::convert::Infallible), which has no values. So a
/// `Control<Infallible>` can never hand one out, and the arm a `run` body writes for it is
/// exhaustive with NO arms — the compiler's own proof that an uncontrollable source's control seat
/// costs it nothing:
///
/// ```
/// use ingraph::MutationNode;
///
/// /// What a `run` body would do with a command from an ABSENT mutation seat.
/// fn eat(command: <() as MutationNode>::Command) -> ! {
/// // There is no value of this type, so there is no arm to write. This IS the body.
/// match command {}
/// }
/// ```
///
/// # It is IMPLEMENTED by the mutation declaration
///
/// `#[ingraph::mutation]` emits the row for the node it is written on — `type Command` being the
/// enum that declaration mints, one variant per field. The impl for `()` below is the framework's
/// own and the only one this crate writes.
/// THE ABSENT SEAT: a source with no command face at all.
///
/// [`Infallible`](core::convert::Infallible) and not a unit of this crate's own, because the claim
/// being made is exactly the one an uninhabited type makes: there is no command, so there is no
/// value, so the arm is dead by construction rather than by convention. See the trait's own note for
/// the law and for why [`Noop`](crate::Noop) is not this.
/// HOW ONE EXCHANGE FAILS, as its declaration said it does — the three-tier signature, as a fact.
///
/// The `error(…)` word inside a field's `handler(…)` block has three legal shapes and they are the
/// three arms here. Which arm a field is in decides the handler signature the emission demands, so
/// this is the same fact read from the other end:
///
/// | written | this arm | the handler returns |
/// |---|---|---|
/// | nothing | [`Never`](Self::Never) | `Response` — no `Result` at all |
/// | `error(message = "…"[, code = "…"])` | [`Canned`](Self::Canned) | `Result<Response, ()>` |
/// | `error(type = "…"[, code = "…"])` | [`Rich`](Self::Rich) | `Result<Response, TheType>` |
///
/// A CANNED failure's words live in the declaration and never in the handler: the message and the
/// code are fixed at the word, so the body reports only the POSITION it failed at, which is what
/// `Err(())` is. A RICH one's words live in the error value, and the code (where one was written) is
/// the heading over whatever that value renders as.
/// ONE DECLARED EXCHANGE, as the declaration wrote it.
///
/// The per-field words of the mutation grammar, in the shape a reader spends them: which field, what
/// the wire calls it, which handler runs it, whether that handler is awaited, what it was granted,
/// and how it fails. Every one of them is `const`-constructible, because the whole table is an
/// associated constant — [`Upstream`](crate::Upstream)'s own reason, one layer over: a node's
/// exchanges are a fact about its declaration and not a value anybody computes.
///
/// # It carries PATHS and never types
///
/// `handler`, the granted resources and a [`Rich`](Fallibility::Rich) failure's type are all strings.
/// Unlike [`Upstream`](crate::Upstream), there is no identity to join on here: what the emission does
/// with a handler path is CALL it, and what a caller does with this record is read it. So the
/// strings are what the declaration wrote, carried for the sentence — and a rename, an alias or a
/// re-export changes them without changing what was called.
/// **WHAT ONE MUTATION NODE DECLARED** — the facts its own expansion states, for the readers that
/// cannot see its tokens.
///
/// [`Declared`](crate::Declared)'s shape one layer over, and for the same wall: two macro expansions
/// cannot read each other, so a node STATES its facts as a trait impl and whoever needs them NAMES
/// them through a projection. A source's own expansion never sees the mutation declaration it
/// mounts; what it sees is `<WatchOps as DeclaredMutation>::…`.
///
/// ```ignore
/// impl DeclaredMutation for WatchOps {
/// const ALL_SYNC: bool = false;
/// const EXCHANGES: &'static [Exchange] = &[
/// Exchange::of("add", "crate::watch::add")
/// .renamed("addWatch")
/// .awaited()
/// .granting(&["crate::Catalog"])
/// .failing(Fallibility::Rich { named: "crate::AddWatchError", code: Some("ADD_FAILED") }),
/// ];
/// }
/// ```
///
/// # It is a PUBLIC seam, exactly as [`Declared`](crate::Declared) is
///
/// Every item is hand-writable and every one is defaulted, so a hand-written node that has already
/// written its [`MutationNode`] row joins with `impl DeclaredMutation for MyOps {}` and states the
/// honest nothing. A node is not obliged to be generated to be mounted.
/// **WHAT ONE ORIGIN DECLARED** — the facts a launch walk needs and a root's own declaration cannot
/// see.
///
/// [`Declared`](crate::Declared)'s shape for the origin layer, and it exists for the same wall: a
/// walk that mounts an origin sees a TYPE and nothing else, so the origin's own expansion STATES
/// what it is and the walk NAMES it through a projection.
///
/// ```ignore
/// impl DeclaredOrigin for Watch {
/// type Mode = Block;
/// const MOUNTS: Option<&'static str> = Some("WatchOps");
/// }
/// ```
///
/// # It is a PUBLIC seam, exactly as [`Declared`](crate::Declared) is
///
/// `#[ingraph::source]` emits the row, and a hand-written origin writes one — three lines, one of
/// which is defaulted. An origin is not obliged to be generated to be mounted.
/// HOW A STREAMING LIFE ENDED — the `Ok` half of what a `run` answers, at either of the two layers
/// that have one.
///
/// # TWO layers spend it, and it is one vocabulary rather than two
///
/// An ORIGIN's `run` is the whole line's life; a [`StreamOperator`](crate::StreamOperator)'s `run` is
/// ONE DELIVERY's. Both stream through a bounded [`Feed`], both hear a [`ShutdownSignal`], and both therefore
/// end in exactly the two ways this enum names — so the streaming compute face reuses these words
/// verbatim rather than minting a parallel set. A stream-specific endings enum was drafted and
/// refused on that reading: its one extra fact is one the fate payload already carries.
///
/// Read the arms at the streaming face as the same sentence about a smaller life: [`Spent`](Self::Spent)
/// is the delivery streamed to its end, [`Stopped`](Self::Stopped) is the wind-down.
///
/// # The vocabulary is CLOSED, because the axis has two ends
///
/// A line that ENDED either ran out of its own accord or was told to. There is no third thing for a
/// finished run to have done, so this is a closed enum rather than an open one: the same reading
/// [`Selects`](crate::Selects) states for the mode axis, and the reason neither carries
/// `#[non_exhaustive]`.
///
/// A source that DIED — the socket gone, the disk refusing, the API answering 500 forever — did not
/// reach either ending, and it does not report one. It returns `Err` carrying its own
/// [`Error`](Source::Error), which is why this enum could stay two-armed rather than growing a third
/// arm that every `match` in every deployment would have to learn.
///
/// # It is a REPORT and not a verdict
///
/// Both endings are ordinary. A finite origin that reaches its last item is [`Spent`](Self::Spent)
/// and has done exactly what it was for; an infinite one that hears the stop is
/// [`Stopped`](Self::Stopped) and has done exactly what it was for. What the framework does with the
/// answer is tell the truth about it — which of the two a run record carries, and nothing else.
///
/// # Not [`Stopped`](crate::Stopped), one name over
///
/// That type is a whole DEPLOYMENT's shutdown report — who settled, who did not, what was left
/// untorn. This is ONE origin's ending. The words are close because the facts are adjacent, and an
/// account that added them into one column would be counting two different things.
/// THE STOP LINE, from the BODY's side: the one thing the framework ever says to a running node.
///
/// Reached through the node's own window — [`Context::shutdown`] — at every face of this crate, and
/// it is one type at all of them: an origin's whole life, a streaming delivery's, an autonomous
/// node's loop and a buffered `accept` all hear the wind-down on this.
///
/// It carries nothing beyond itself — *stop taking new work* — exactly as the shutdown registry's
/// own announcement does, and it coalesces for the same reason: a second stop is the same
/// instruction, and a slot that held two would make a body able to hear it twice.
///
/// # Three doors, and they ask different questions
///
/// - [`is_shutdown`](Self::is_shutdown) LOOKS. Non-blocking, repeatable, and what a loop with work
/// of its own asks once per pass — a walk between directories, a poller between polls.
/// - [`heard`](Self::heard) WAITS. What an origin with nothing else to do parks on, so a source that
/// is purely reactive costs no spin.
/// - [`arm`](Self::arm) is the same wait AS ONE ARM OF A SELECT. What a body that also waits on
/// edges and on a crew of its own puts beside them, so the stop is heard in the same park as
/// everything else rather than one sweep late.
///
/// The look is repeatable and never consumes, which is [`Enrolled::winding`](crate::Enrolled)'s
/// measured shape one layer up: an answer that consumed itself would be true exactly once, and a
/// loop that asked twice would be told the wrong thing the second time.
///
/// # A stop line whose other half LETS GO reads as stopped
///
/// Both doors answer that way, and it is the same instruction arriving by a different road: nobody
/// is left to ask this source for anything, so continuing would be work with no reader. It is what
/// makes a dropped world a shutdown rather than a hang.
///
/// It is SAID rather than inferred, which is [`Stopper`]'s own [`Drop`]: a mounted origin's line has
/// TWO halves — the deployment's and the shutdown chain's — so *every sender is gone* would be a
/// road neither of them could take alone. The disconnect still answers the same way underneath, for
/// a line whose halves went without a word.
///
/// # The fact LATCHES, which is what makes the two doors agree
///
/// A park has to take the announcement out of its slot to return from it, and a look that read only
/// the slot would then answer *no* to a source that had just heard *yes*. So the taking is recorded:
/// once said, this line reads as stopped forever, by either door, in either order. A stop is not a
/// thing that can be un-said.
/// THE STOP LINE, from the FRAMEWORK's side — what says *wind down* to one running source.
///
/// Minted with its [`ShutdownSignal`] by [`shutdown_signal`], one pair per source. It is the origin layer's own half of
/// the announcement the shutdown registry makes to every other party
/// ([`Party::announce`](crate::Party::announce)): the same coalescing capacity-one slot, said the
/// same way, and separate because a source's engine keeps the [`Enrolled`](crate::Enrolled) that
/// carries the settle — handing the source that handle would hand it the power to declare itself
/// finished.
///
/// # LETTING GO SAYS IT, and that is a [`Drop`] rather than the transport's physics
///
/// A mounted origin's line has TWO halves: the one that comes back in
/// [`Mounted`](crate::Mounted), and the one the launch keeps so that
/// [`App::shutdown`](crate::App::shutdown) can wind an infinite origin down. So *the last sender is
/// gone* is a road NEITHER of them can take alone, and a handle that let go silently would leave the
/// origin running on the strength of a half nobody holds any more.
///
/// The drop therefore ANNOUNCES. Both halves say the same thing whichever order they go in, a second
/// announcement coalesces into the first, and the disconnect still answers underneath for a
/// [`ShutdownSignal`] whose halves went without a word.
///
/// NOT `Clone`, where [`Commands`] is, and the reason survives the paragraph above: a clone is a
/// party that can say stop, and with the drop above a clone forgotten somewhere would say it — so an
/// extra half is minted at the ONE place that has a reason for one, which is the mount.
/// LETTING GO SAYS *stop* — see the type's own note for why this is a [`Drop`] and not the
/// transport's disconnect.
/// Mint one source's stop line: the framework's [`Stopper`] and the source's [`ShutdownSignal`].
///
/// Capacity ONE and nothing to configure, because the message carries nothing beyond itself — see
/// [`Stopper::announce`] for what a second one does.
/// THE FEED: where a streaming body puts what it produces, one item at a time.
///
/// # TWO layers give through it
///
/// An ORIGIN feeds for the whole life of its line, and a
/// [`StreamOperator`](crate::StreamOperator) feeds for the whole life of ONE DELIVERY. The seat is
/// the same one in both places, for the reason [`Fin`] is: what the two lives do — produce more than
/// fits, over a line somebody else drains — is the same thing at two scales, and the wait below is
/// what makes both honest. At the compute face the LINE CLOSES when `run` returns, because the feed
/// was taken by value; at the origin face it closes for the same reason at the end of the line.
///
/// # BOUNDED, and the wait is the point
///
/// The line has a capacity and [`give`](Self::give) WAITS for room on it. That is the framework's
/// default posture rather than this seat's own choice — a bounded edge that blocks is what makes
/// backpressure reach the party generating the work — and it is what keeps a fast origin from
/// filling memory with items a slow graph has not looked at yet.
///
/// [`try_give`](Self::try_give) is the door for an origin that would rather do something else than
/// wait, and it is the caller's decision because only the caller knows what that something else is.
///
/// # Both faces, from one organ
///
/// [`give`](Self::give) blocks the thread and [`give_async`](Self::give_async) parks a task, and
/// they are one channel rather than two: the transport spans both faces natively, which is what lets
/// the same seat serve a [`Source`] and an [`AsyncSource`] with no bridge between them.
///
/// # The [`Sink`](futures_sink::Sink) face
///
/// [`Feed`] wears it so that a body written with somebody else's sink combinators can spend this
/// seat. Two honest notes about what the transport's own implementation promises:
///
/// - `poll_ready` is OPTIMISTIC. It does not reserve room; readiness is answered without asking the
/// queue, and the wait for space happens at `poll_flush`. So a sink caller gets the same
/// backpressure [`give`](Self::give) does, one call later than the trait's shape suggests.
/// - `poll_close` FLUSHES and does not disconnect. The line closes when the [`Feed`] is dropped,
/// which is the moment a source's `run` returns.
///
/// # `Y: 'static`, and it is what OWNING the sink face costs
///
/// A [`Sink`](futures_sink::Sink) is a registration that outlives one poll: an item staged by
/// `start_send` and a wait for room that has to still be waited on when the next poll comes are
/// state this seat HOLDS, and a transport can only hold that state for a value that outlives it. It
/// is not a bound this layer chose — a borrowed registration would be self-referential — and it costs
/// a source nothing real: a yield crosses a channel into a party scheduled independently of the one
/// that made it, so a yield borrowing its producer's stack is not a shape that could be wired.
///
/// # THE LINE HAS TWO SHAPES, and an origin's body cannot tell which it holds
///
/// | shape | what the far end is | minted by |
/// |---|---|---|
/// | LOOSE | a [`Yielded`] the deployment drains itself | [`feed`] |
/// | BRIDGED | a CONSUMER'S OWN INBOX — the edge, held by its producing end | [`bridging`](Self::bridging) |
///
/// Everything above is true of both, and that is the bridge's whole design: an origin writes one
/// `run` and the arrangement decides where its items land. See [`bridging`](Self::bridging) for what
/// the second shape does at each door, and `drive::launch::origin` for why the edge is handed to the
/// origin rather than pumped into it.
/// WHERE A [`Feed`]'s items actually go — the two shapes, and the one place they differ.
///
/// An enum rather than two types, because the SEAT is one seat: an origin's body is handed a
/// `Feed<Y>` and must not be able to ask which arrangement it is in. The discriminant is one
/// perfectly-predicted branch in front of a channel send, which is the cost this shape is worth
/// paying — the alternative measured on this transport is in [`MemoryAware`](crate::MemoryAware)'s
/// note, and it is two atomics rather than a tag.
/// THE EDGE, WEARING A FEED'S FACE: a consumer's inbox and the token counter that feeds it.
///
/// # What a give becomes
///
/// A graph edge carries a [`Delivery`] — items under [`ItemId`]s, inside an ack window a consumer
/// releases — and a feed carries the bare `Y`. This is where the one becomes the other, and both
/// halves of that conversion are rulings rather than details:
///
/// - **THE ID** is minted here, from a counter of this line's own, exactly as every other sender in
/// the framework mints one. Monotone within one sender and meaningless across two, which is the
/// whole of what [`ItemId`]'s contract asks. [`Ordering::Relaxed`] is enough for that: what the
/// window needs is UNIQUENESS per sender, and the only party that could read an ordering off these
/// tokens is the one this line deliberately does not have.
/// - **THE WINDOW** is opened per give and, at the PLAIN doors, its receiving half is dropped on the
/// spot. That is not a shortcut — it is the position an origin is IN. An ack releases custody
/// UPSTREAM, and there is nobody upstream of a head to release it to; a source has no durable
/// position to rewind to and nothing to re-deliver from. The protocol already has this outcome
/// written down: a consumer answering into a hung-up token is answering nobody, and that is not an
/// error to handle. It is the same posture an app's own feeder takes through
/// [`App::feeder`](crate::App::feeder), which is the road this one is the framework-side twin of.
///
/// The ACKED doors ([`Feed::give_acked`]) are the same window with the receiving half KEPT, which
/// is the whole of their difference: the same send, on the same line, in the same order, under the
/// same bound — so an acked give and a bare one on one feed are one ordering regime and one
/// backpressure regime, and the only thing the acked one does more is hold on to what the plain one
/// throws away.
/// **ONE ACKED GIVE'S RECEIPT**: which item went out, WHAT it was, and the answer it is owed.
///
/// # It is the window's receiving half with a key beside it
///
/// The two facts, and neither is enough alone. The [`AckReceiver`] is where the answer arrives, and
/// the [`ItemId`] is which of that answer's per-item slots belongs to THIS give — a released set and
/// a receipt map are both keyed, so a receipt that held only the receiver could read neither.
///
/// # `M` IS THE MESSAGE THAT WAS GIVEN, and it is what makes [`receipt`](Self::receipt) typed
///
/// The parameter carries no value — it is `PhantomData<fn() -> M>`, so the type is `Send`, `Sync`
/// and covariant whatever `M` is — and what it carries is the FACT: this receipt is the answer to
/// one item of `M`, because [`Feed<Y>`](Feed) only ever hands one back from a give of a `Y`.
///
/// That fact is the whole of the receipt seat's producer side. `<M as Receipts>::Receipt` is the
/// type the message's own declaration named, so `feed.give_acked(open)?.receipt()` binds the answer
/// with no turbofish, no node named and nothing for the two ends of the edge to disagree about — and
/// it reads the same from any feed, whatever is mounted on the far end. A producer cannot name the
/// consumer of its own edge; it always knows what it gave. A message that declares NO receipt is
/// `E0277` at this call rather than a runtime [`Unreceipted::Silent`], which is a wiring mistake
/// answered where it was made.
///
/// A bridged give sends exactly one item as one delivery, so the answer this receipt waits for speaks
/// for exactly this item and nothing else. That is what lets [`receipt`](Self::receipt) be one call
/// rather than a lookup a caller performs.
///
/// # Concurrent siblings need no router
///
/// Every give opens its OWN window and this receipt holds its OWN receiving half, so N workers each
/// holding a clone of one [`Feed`] and each parked on its own acked give are N independent oneshots.
/// Nothing demultiplexes, nothing is shared, and no answer can reach the wrong awaiter — the routing
/// the ruling asks for is a consequence of the protocol already being per delivery, not a mechanism
/// added on top of it.
///
/// # Dropping it is legal, and it is the plain give
///
/// A receipt dropped unread hangs up its own token, which is precisely what
/// [`give`](Feed::give) does at the moment it sends. So a body that asked for an answer and changed
/// its mind costs the consumer nothing: it answers into a token nobody holds, which the protocol
/// already calls answering nobody.
/// WHY AN ACKED GIVE WAS REFUSED — the two facts, and the item is in the refusal either way.
/// **THE ACKED GIVE WAS REFUSED**, and here is the item back.
///
/// [`Unfed`]'s shape with a REASON beside the item, and the reason is why it is a second type rather
/// than that one: `Unfed`'s whole design is one sentence for two failures a caller distinguishes
/// through [`Feed::is_disconnected`], and this door has a third fact that read cannot answer — a
/// loose feed is refused for a reason that has nothing to do with the line's state.
/// THE ITEM WAS NOT TAKEN, and here it is back.
///
/// One refusal for the two ways a give can fail — no room on an impatient door, or nobody there at
/// all — because [`Feed::is_disconnected`] is what tells them apart and the caller that wants the
/// distinction is the one that has to decide about it. [`give`](Feed::give) waits for room, so the
/// only way IT refuses is the second.
///
/// It carries the item because a refused give is not a loss until somebody decides it is: a source
/// holding the value can spool it, re-key it, or end — and one that was handed a bare failure could
/// only end. A [`StreamOperator`](crate::StreamOperator) is handed the same refusal in the same
/// words, and its usual reading of one is [`Fin::Stopped`]: nothing downstream is left to stream to.
///
/// # Why a type rather than the item alone
///
/// [`Outbox::deliver`](crate::Outbox::deliver) one layer down answers `Result<(), Delivery<…>>` —
/// the value itself, no wrapper — and this seat cannot, because
/// [`Sink::Error`](futures_sink::Sink::Error) is a type the trait names. Handing the sink face a
/// wrapper and the direct face a bare value would be two spellings of one fact, so both spell this.
/// THE CONTROL LINE, from the SOURCE's side: the typed commands an app says to a running origin.
///
/// A watcher's roots change while it runs, and the party that knows they changed is outside the
/// graph. So the framework ships the seat — one line, one command type, minted from the mutation
/// node the source mounts — rather than leaving every controllable origin to invent its own.
///
/// # PROVIDED, never mandated
///
/// `run` is still the author's whole life. A source may ignore this seat entirely, mount `()` and
/// run a listener of its own inside `run` — its server, its protocol, its state. What the seat buys
/// is uniformity: typed commands, a programmable app face, and a landing spot for the wire verbs
/// that answer them. It revokes nothing.
///
/// # A source EATS commands; it does not answer them
///
/// The answer was already given. A field's handler validated the request, did its work through the
/// resource it was granted, and receipted — and only THEN did the framework mint the command and send
/// it here. So this line is one-way and carries only successes: a change that failed has no living
/// application, and a *wrong command* arm is not a thing a body can be written to have.
///
/// # The [`Stream`](futures_core::Stream) face
///
/// [`Control`] wears it for [`Feed`]'s reason — so an awaited body can spend the seat with somebody
/// else's combinators — and holds TWO handles onto one queue to do it: the direct face's, and the
/// stream's own, which the transport hands out one-way ([`Feed`] needs only one, its sink face
/// lending its sender back).
///
/// NOTHING CAN BE STRANDED BETWEEN THEM, and it is a property of the transport rather than of the
/// order a body happens to ask in: a send that finds a waiting STREAM signal wakes it and leaves the
/// item in the QUEUE — flume 0.12's `Shared::send`, re-read there, which is where the *was async and
/// a stream, so didn't acquire the message* arm is — so whichever face asks next is the one that
/// gets it. `tests::the_control_wears_the_stream_face` is what holds that here, since a version bump
/// could change it.
///
/// # `C: 'static`, for [`Feed`]'s reason exactly
///
/// The stream face is a registration that outlives one poll, and a transport can only own one for a
/// value that outlives it. A command is minted by a handler and applied inside a loop that was
/// already running when it was minted, so a command borrowing anything is not a shape that could be
/// said.
/// THE CONTROL LINE, from the APP's side — what says a command to one running source.
///
/// Minted with its [`Control`] by [`control`], and what a launch hands back per mount whose mutation
/// seat is not `()`. It is `Clone` for [`Outbox`](crate::Outbox)'s reason: a handle is what several
/// parties hold onto one line, and cloning one is what makes an app able to answer two wire verbs
/// from two tasks.
// Hand-written so `C` need not be `Clone`: a sender is a handle, and cloning one is what several
// parties holding one line IS.
/// Mint one source's control line of `capacity`: the app's [`Commands`] and the source's
/// [`Control`].
///
/// BOUNDED, as every line in this framework is by default: a control line that grew without bound
/// would let an app queue work a source will never catch up with, and the wait is what tells the app
/// so.
/// THE FEED LINE, from the FRAMEWORK's side — where a source's items are taken out.
///
/// Minted with its [`Feed`] by [`feed`]. What holds one in a running deployment is the intake at the
/// head of the graph; what holds one in a test is the test.
/// Mint one source's LOOSE feed line of `capacity`: the source's [`Feed`] and the framework's
/// [`Yielded`].
///
/// BOUNDED, and the wait for room is the backpressure — see [`Feed`]'s own note.
///
/// The OTHER shape has no pair to mint and therefore no function here: a bridged feed's far end is a
/// consumer's inbox, which the wiring walk already opened, so what it takes is that edge rather than
/// a depth — see [`Feed::bridging`].
/// AN ORIGIN, on the BLOCKING face — a scanning walk, a blocking socket loop, a directory watcher
/// whose library calls block.
///
/// # `type Options` is the AUTHOR's, and a knobless origin writes `()`
///
/// Bound by nothing here, per [`AsyncConstructor::Options`](crate::AsyncConstructor)'s discipline:
/// what options must satisfy is the DEPLOYMENT's question — a section read out of a file has to
/// deserialize — and that is asked where the sections are declared rather than where one is spent.
///
/// It is the ONE seat, and the emitted options spine is written off it: an origin's
/// `[<mount>]` section holds exactly this type, and [`Creation::origin`](crate::Creation::origin)
/// hands it to [`build`](Self::build). An origin used to state its knobs a second time through an
/// [`AsyncConstructor`](crate::AsyncConstructor) the walk read instead of this one; that detour is
/// retired and the seat below is what a deployment fills.
///
/// # `type Yield` is MONO-TYPED
///
/// One origin produces one kind of item. An origin whose subject really is several kinds writes the
/// sum itself and a splitter operator downstream — which is exactly what an emitted port would cost
/// at the arities a control-rate origin has, and is why no port vocabulary is invented here.
///
/// # `type Error` is the AUTHOR's too, and BOTH verbs spend it
///
/// Bound-free, per [`Operator::Error`](crate::Operator)'s discipline: a construction refuses in its
/// own currency and the launch layer names the source when it wraps one.
///
/// ONE currency for the two verbs, and not two seats. A source that cannot open its socket and one
/// whose socket dies an hour later have the same thing to say, in the same words, to the same
/// reader; a second error seat would make an author decide which half of one vocabulary a variant
/// belongs to, and would make a launch that renders both render them two ways.
///
/// | what happened | what `run` answers |
/// |---|---|
/// | ran out of its own items | `Ok(`[`Fin::Spent`]`)` |
/// | heard the stop and wound down | `Ok(`[`Fin::Stopped`]`)` |
/// | DIED — it neither finished nor was stopped | `Err(Self::Error)` |
///
/// # `build` is SYNCHRONOUS here, and AWAITED on the other face
///
/// What a construction reaches for is the [`Resources`] the create walk has filled, and every door
/// on it answers at once: the resources were built by the pass before, and looking one up is a typed
/// read of a map. So a BLOCKING origin's `build` needs no future — and [`AsyncSource::build`] is
/// awaited all the same, per [`AsyncConstructor::with_options`](crate::AsyncConstructor)'s shape one
/// tier over, because an awaited origin whose opening is real work (a socket to dial, a session to
/// authenticate) has an `.await` to spend before its first item and nowhere else to spend it.
///
/// # Examples
///
/// ```
/// use ingraph::{Context, Control, Feed, Fin, Resources, Source};
///
/// /// An origin with a last item: it hands out `n` numbers and is spent.
/// struct Counting {
/// remaining: u64,
/// }
///
/// impl Source for Counting {
/// type Options = u64;
/// type Yield = u64;
/// type Mutation = ();
/// type Error = core::convert::Infallible;
///
/// fn build(_ctx: &Resources, remaining: u64) -> Result<Self, Self::Error> {
/// Ok(Self { remaining })
/// }
///
/// fn run(
/// mut self,
/// ctx: Context,
/// feed: Feed<u64>,
/// _control: Control<core::convert::Infallible>,
/// ) -> Result<Fin, Self::Error> {
/// while self.remaining > 0 {
/// if ctx.shutdown().is_shutdown() {
/// return Ok(Fin::Stopped);
/// }
/// if feed.give(self.remaining).is_err() {
/// // Nothing downstream will take another one.
/// return Ok(Fin::Stopped);
/// }
/// self.remaining -= 1;
/// }
/// Ok(Fin::Spent)
/// }
/// }
///
/// let (feed, yielded) = ingraph::feed(8);
/// let (_commands, control) = ingraph::control(1);
/// let (_stopper, stop) = ingraph::shutdown_signal();
///
/// // The CREATE window and the RUNTIME one, in the order the framework mints them: the map first,
/// // the mounted node's own window second.
/// let built = Resources::new();
/// let counting = Counting::build(&built, 3).unwrap();
///
/// let ctx = Context::new("counting").halting(stop);
/// assert_eq!(counting.run(ctx, feed, control), Ok(Fin::Spent));
/// assert_eq!(yielded.drain().collect::<Vec<_>>(), vec![3, 2, 1]);
/// ```
/// [`Source`]'s AWAITED face — the same origin, for a life that has an `.await` to spend.
///
/// Everything [`Source`] states holds here verbatim: the same three seats with the same types, the
/// same [`Fin`], the same one error currency for both verbs. THE DIFFERENCE IS THAT BOTH VERBS ARE
/// FUTURES — the life, and the opening that precedes it.
///
/// # Why a PAIR and not a defaulted second verb
///
/// The dual-mode law, stated in full at [`AsyncOperator`](crate::AsyncOperator): an author
/// implements EXACTLY ONE face and the bound is what says which. A single trait carrying both verbs
/// would make every origin answer a question it has no body for, and a blanket bridge would blind
/// the bound that selects.
///
/// # NEITHER future carries `Send` — [`AsyncOperator::accept`](crate::AsyncOperator)'s law, applied
///
/// A `!Send` origin is a supported shape — an origin holding a model session, a `!Send` client, a
/// handle pinned to one thread — and a bound written HERE would refuse it at the declaration rather
/// than at the engine that could not place it. So the trait states the CONTRACT and the DRIVER
/// states its own requirement: an engine that spawns a task pins `Send` at the mount, where the
/// engine is chosen, and an origin that cannot cross threads is refused THERE with the engine named
/// — or placed on the thread driver, which asks for nothing.
///
/// This is the same division `accept` is under one tier down, and the same one
/// [`AsyncConstructor::with_options`](crate::AsyncConstructor) is under: the trait is the author's
/// contract, mobility is the placement's question, and the two are not written in one place.
///
/// # Examples
///
/// ```
/// use ingraph::{AsyncSource, Context, Control, Feed, Fin, Resources};
///
/// /// An origin that never ends of itself: it hands out numbers until it is told to stop.
/// struct Ticking;
///
/// impl AsyncSource for Ticking {
/// type Options = ();
/// type Yield = u64;
/// type Mutation = ();
/// type Error = core::convert::Infallible;
///
/// async fn build(_ctx: &Resources, _options: ()) -> Result<Self, Self::Error> {
/// Ok(Self)
/// }
///
/// async fn run(
/// self,
/// ctx: Context,
/// feed: Feed<u64>,
/// _control: Control<core::convert::Infallible>,
/// ) -> Result<Fin, Self::Error> {
/// let mut tick = 0;
/// loop {
/// if ctx.shutdown().is_shutdown() {
/// return Ok(Fin::Stopped);
/// }
/// if feed.give_async(tick).await.is_err() {
/// return Ok(Fin::Stopped);
/// }
/// tick += 1;
/// }
/// }
/// }
///
/// # tokio::runtime::Builder::new_current_thread().build().unwrap().block_on(async {
/// let (feed, yielded) = ingraph::feed(4);
/// let (_commands, control) = ingraph::control(1);
/// let (stopper, stop) = ingraph::shutdown_signal();
///
/// stopper.announce();
/// let built = Resources::new();
/// let ticking = Ticking::build(&built, ()).await.unwrap();
///
/// let ctx = Context::new("ticking").halting(stop);
/// assert_eq!(ticking.run(ctx, feed, control).await, Ok(Fin::Stopped));
/// assert!(yielded.is_empty());
/// # });
/// ```