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
//! The NEWTYPE DEVICE's model: what `#[derive(ingraph::NewType)]` emits for a single-field struct
//! this crate declares — one citizenship row per KIT the declaration opted into, every one of them a
//! pass-through to the type inside.
//!
//! # What it is, beside the three devices that already existed
//!
//! | device | the type it equips | what it knows about that type |
//! |---|---|---|
//! | `#[derive(ingraph::Enum)] #[ingraph(remote = "…")]` | a vocabulary SOMEBODY ELSE declared | its variants, restated |
//! | `#[ingraph::entity(remote = "…")]` / `record(remote)` | a struct SOMEBODY ELSE declared | its fields, restated |
//! | `#[derive(ingraph::Filter)] #[ingraph(operator(<family>))]` | a value THIS crate declares | that it is one operand — and it MINTS the filter |
//! | **this** | a value THIS crate declares | that it WRAPS one, and which faces it wants |
//!
//! The line between the last two is the CONSTRUCTION CONTRACT. The element mode mints a filter type
//! and gives the element the citizenship that filter needs, whole and unchosen; this device chooses,
//! and every face it writes is the INNER type's answer wearing the outer type's name. So a newtype
//! that wants a filter and nothing else takes two words, and one that wants to be a column in two
//! dialects and never crosses a wire takes two others.
//!
//! # THE EMISSION LAW: every pass-through is FULLY QUALIFIED
//!
//! `<Inner as Trait>::method(&self.0, …)`, never `self.0.method(…)`, and the associated types and
//! consts alike. Four things follow from it, and the fourth is the one that decides it:
//!
//! - **method resolution is pinned.** A bare `self.0.push_bind(qb)` resolves by autoref and by
//! inherent-before-trait, so an inner type growing an INHERENT method of that name silently takes
//! the call away from the trait the row is implementing.
//! - **the obligation's landing point IS the diagnostic's.** The row carries `Inner: Trait` in its
//! `where` clause, so a missing kit on the inner type is `E0277` naming that type and that trait,
//! at the declaration — rather than a method-not-found inside an expansion.
//! - **it is the house's own absolute-path doctrine**, one grain in: an emission spells every
//! framework name from a root, and a delegation spells every callee from its trait.
//! - **one spelling serves every receiver and every carrier.** `&self`, `self`, no receiver at all,
//! an associated const, a GAT — the qualified form is the same shape for all of them, and it is
//! the only shape that is also correct where the inner type is a GENERIC PARAMETER. `self.0.cmp(…)`
//! on a `Confidence<S>` cannot say which `S`'s row it meant; `<S as Trait>::cmp(&self.0, …)` can.
//!
//! # The GATE is one source, and every READ path is spent on it
//!
//! A newtype that carries an invariant has exactly one door — `scalar(parse = "…")` for a value read
//! WIDE out of text, `scalar(check = "…")` for one anchored in a range — and the device spends that
//! door on every path a value ARRIVES on: the scalar's `parse`, its `is_valid`, the cursor's
//! `read_cursor`, and the dialect decode. What has no gate to spend passes straight through.
//!
//! The asymmetry is the point. A WRITE is a value the type already holds, so nothing can be wrong
//! with it and the inner's own row is the whole answer. A READ is bytes somebody else wrote — a
//! client's cursor, a column another writer filled, a JSON operand — and a newtype whose type says
//! `[0.0, 1.0]` must not be handed a `1.5` because it came back from a column.
use quote::{format_ident, quote};
use syn::ext::IdentExt as _;
use crate::{element::ElementFamily, model::DatabaseKind};
#[cfg(test)]
mod tests;
/// The DOOR a declaration put in front of its own values — `scalar(parse = "…")` or
/// `scalar(check = "…")`, and never both.
///
/// Both name a free function returning `Result<Self, E>` with `E: Display`. What differs is the
/// SHAPE the function is handed, and the difference is the whole reason there are two words: a text
/// door reads spellings and folds them, a check door takes the carrier's own value and says whether
/// it is in range.
#[derive(Clone)]
pub enum Gate {
/// `parse = "…"` — `fn(&str) -> Result<Self, E>`. Text in, WIDE: the function owns the grammar,
/// the folds and the refusal.
Parse(syn::Path),
/// `check = "…"` — `fn(Inner) -> Result<Self, E>`. The carrier's own value, ANCHORED: an
/// interval, a normalisation, a domain the width admits and the type does not.
Check(syn::Path),
}
/// The `scalar` kit, as a declaration wrote it.
#[derive(Clone, Default)]
pub struct ScalarKit {
/// `rename = "…"` — the name a SCHEMA writes, where the Rust one is not it.
pub rename: Option<String>,
/// The door, where the declaration put one in front of its values.
pub gate: Option<Gate>,
}
/// Every kit a declaration opted into.
///
/// PLAIN, for [`ElementModel`](crate::element::ElementModel)'s reason — public fields, no
/// constructor, no validation. What is checked is checked at the FRONT END, where the tokens an
/// author wrote are still in hand and a refusal can point at one.
#[derive(Default)]
pub struct Kits {
/// `graphql(async_graphql(scalar(…)))` — the type's own GraphQL scalar.
pub scalar: Option<ScalarKit>,
/// `graphql(async_graphql(input))` — [`ToGraphqlInput`].
pub input: bool,
/// `graphql(async_graphql(output))` — [`ToGraphqlOutput`].
pub output: bool,
/// `marker(<family>)` — the interpretation a FIELD of this type is read under.
pub marker: Option<ElementFamily>,
/// `filter` — the family's filter, reached through a reading this device mints.
pub filter: bool,
/// `cursor` — [`CursorValue`], a keyset position.
pub cursor: bool,
/// `sqlite` / `postgres` / `mysql` — the dialects this type is a column in.
pub databases: Vec<DatabaseKind>,
}
impl Kits {
/// Whether the declaration asked for ANYTHING.
#[must_use]
pub fn is_empty(&self) -> bool {
self.scalar.is_none()
&& !self.input
&& !self.output
&& self.marker.is_none()
&& !self.filter
&& !self.cursor
&& self.databases.is_empty()
}
/// The door, where one was declared — `scalar`'s, since that is the only block it lives in.
#[must_use]
pub fn gate(&self) -> Option<&Gate> {
self.scalar.as_ref().and_then(|scalar| scalar.gate.as_ref())
}
}
/// A declared NEWTYPE, as the device reads it.
pub struct NewTypeModel {
/// The declaration's own visibility, which a minted reading takes.
pub vis: syn::Visibility,
/// The newtype the faces are OF.
pub subject: syn::Ident,
/// Its parameters, carried onto every emitted row.
pub generics: syn::Generics,
/// The `ingraph` root the expansion spells its shelf through.
pub krate: syn::Path,
/// The single field the value is held in — positional or named.
pub member: syn::Member,
/// That field's type, which every pass-through delegates to.
pub inner: syn::Type,
/// The kits the declaration opted into.
pub kits: Kits,
}
impl NewTypeModel {
/// A path to one of the names the framework SHELVES, reached the ONE way emitted code may reach
/// them.
fn framework(&self, module: &[&str], name: &str) -> proc_macro2::TokenStream {
crate::emit::framework(&self.krate, module, name)
}
/// A whole VENDORED crate on that shelf, as the string an attribute's `crate = …` takes.
fn vendored(&self, name: &str) -> String {
crate::emit::vendored(&self.krate, name)
}
/// This newtype's name as a SCHEMA writes it.
///
/// The Rust name unraw'd, unless `rename = "…"` moved it. The knob exists where
/// `#[derive(ingraph::Enum)]` has none, and the difference is which name is DERIVED: a vocabulary
/// publishes the name of a type somebody else declared, so a rename there would be this crate
/// renaming a foreign schema entity. A newtype is THIS crate's, and the wire name it publishes is
/// its own commitment to make.
fn sdl(&self) -> String {
self
.kits
.scalar
.as_ref()
.and_then(|scalar| scalar.rename.clone())
.unwrap_or_else(|| self.subject.unraw().to_string())
}
/// The reading this device mints for the filter kit — `<Name>Wire`.
#[must_use]
pub fn reading_name(&self) -> syn::Ident {
format_ident!("{}Wire", self.subject)
}
/// What the minted filter is PUBLISHED as — the operand's schema name, then `Filter`.
///
/// The framework's own naming law, applied where the framework cannot see the type: every filter
/// this crate publishes is `<the operand's schema name>Filter`, and a reading that spelled its own
/// would be free to disagree with the name the operand already publishes.
fn filter_sdl(&self) -> String {
format!("{}Filter", self.sdl())
}
/// The subject as a TYPE — its name with its own parameters, which is what every row is written
/// `for`.
fn subject_type(&self) -> proc_macro2::TokenStream {
let subject = &self.subject;
let (_, ty_generics, _) = self.generics.split_for_impl();
quote!(#subject #ty_generics)
}
/// `Self`, built from one inner value — the shape the field's spelling decides.
fn build(&self, value: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
match &self.member {
syn::Member::Named(ident) => quote!(Self { #ident: #value }),
syn::Member::Unnamed(_) => quote!(Self(#value)),
}
}
/// This declaration's generics with `extra` in FRONT and `predicates` added.
///
/// In front because Rust orders a parameter list lifetimes-then-types and every extra a row here
/// introduces is one or the other in that order; added rather than replaced because a
/// declaration's own bounds are its own — a `Confidence<S: ConfidenceCarrier>` stays one in every
/// row this device writes.
fn generics_with(
&self,
extra: &[syn::GenericParam],
predicates: &[syn::WherePredicate],
) -> syn::Generics {
let mut generics = self.generics.clone();
for (at, param) in extra.iter().enumerate() {
generics.params.insert(at, param.clone());
}
if !predicates.is_empty() {
let clause = generics.make_where_clause();
for predicate in predicates {
clause.predicates.push(predicate.clone());
}
}
generics
}
/// The predicate `Inner: <trait>` — the OBLIGATION every pass-through carries, and the reason a
/// missing kit on the inner type is `E0277` naming that type rather than a resolution failure
/// inside an expansion.
fn owes(&self, bound: &proc_macro2::TokenStream) -> syn::WherePredicate {
let inner = &self.inner;
syn::parse_quote!(#inner: #bound)
}
/// What a TEXT door demands of the WRAPPED type on a read path, and nothing where there is no
/// text door.
///
/// A door declared `parse = "…"` reads SPELLINGS, and what a cursor or a column hands back is the
/// inner type — so the read is routed through that type's own rendering, which is the same text
/// `to_value` writes out. One predicate rather than a bare call, for [`owes`](Self::owes)' reason.
fn rendering(&self) -> Option<syn::WherePredicate> {
match self.kits.gate() {
Some(Gate::Parse(_)) => Some(self.owes("e!(::core::fmt::Display))),
Some(Gate::Check(_)) | None => None,
}
}
/// The whole device, emitted.
///
/// TWO scopes, and the split is the one every emitter here draws: a name the declaring scope has
/// to be able to WRITE goes outside — the minted reading is named by an associated type a
/// downstream crate resolves — and everything else goes inside an anonymous `const`, which is
/// where an emission puts what it owes the declaring scope no name for.
#[must_use]
pub fn emit(&self) -> proc_macro2::TokenStream {
let reading = self.reading();
let markers = self.markers();
let crossings = self.crossings();
let cursor = self.cursor();
let column = self.column();
let stored = self.stored();
let read = self.read();
let key = self.key_delegation();
let id_column = self.id_column_delegation();
let storage = self
.kits
.databases
.iter()
.map(|database| self.storage(*database));
let scalar = self.scalar();
quote! {
#reading
const _: () = {
#markers
#crossings
#cursor
#column
#stored
#read
#key
#id_column
#(#storage)*
};
#scalar
}
}
/// KEY ADMISSION — the one row this device writes that NO kit word asks for.
///
/// Every other row here is opted into: a declaration names `cursor` and gets a keyset position,
/// names `sqlite` and gets a column. This one is unconditional, and the asymmetry is deliberate.
/// The others are FACES a newtype may or may not want; this is a FACT about what a newtype IS —
/// it wraps one value and adds nothing — and a fact does not need asking for. It is also the row
/// with no hand-written alternative from outside the framework: the id vocabulary is sealed, and a
/// declaring crate reaches it through this trait or not at all.
///
/// # Unconditional and yet harmless, because ADMISSION is a consequence rather than this row
///
/// `DelegatesId::Inner` carries no bound: the row says *this type is its inner value* and nothing
/// more, and [`Id`] is granted only where that inner is itself a member. So a
/// `#[derive(ingraph::NewType)] struct Ratio<S>(S)` over a float states the true thing about
/// itself, is not an id, and compiles — where a row that demanded membership here would refuse the
/// declaration outright, and a row spelled `where Inner: Id` would refuse a CONCRETE non-member
/// inner as an unsatisfied trivial bound. Unconditional is the only shape that is additive.
///
/// The `where` clause is the declaration's own, unchanged, for the reason every row here carries
/// it: a `Confidence<S: ConfidenceCarrier>` stays one in this row too.
fn key_delegation(&self) -> proc_macro2::TokenStream {
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let delegates = self.framework(&["id"], "DelegatesId");
let (impl_generics, _, where_clause) = self.generics.split_for_impl();
quote! {
// SAFETY: a newtype holds EXACTLY ONE value — the device refuses a declaration with any other
// count — and this row hands that value back by reference and does nothing else. There is no
// second field, no tag and no width of the outer type's own, so two values are equal exactly
// when their inners are, and every id duty reading the wrapper reads the inner.
#[automatically_derived]
unsafe impl #impl_generics #delegates for #subject #where_clause {
type Inner = #inner;
#[inline]
fn delegate(&self) -> &#inner {
&self.#member
}
}
}
}
/// **THE STORAGE SEAM, READ ONE LAYER OUT** — `ingraph::IdColumn<Db>`, delegating to the value
/// this newtype wraps.
///
/// The second row this device writes that NO kit word asks for, beside
/// [`key_delegation`](Self::key_delegation) — and the SAME reasoning admits it: `IdColumn` is a
/// FACT about what a newtype IS transparent to (its stored form, exactly as `DelegatesId` states
/// its identity), not a face an author chooses, so it costs nothing to emit unconditionally. A
/// `#[derive(ingraph::NewType)] struct Ratio<S>(S)` over a type with no `IdColumn` row of its own
/// simply is not one — `E0277` naming that type at whatever declaration tries to wrap `Ratio` in
/// an id — exactly the shape `key_delegation`'s own note walks through for `DelegatesId` and
/// `Id`.
///
/// # Mirrors `#[derive(ingraph::Id)]`'s OWN row for an id over an id
///
/// That device's `storage` emission already reads the seam one layer out — its own module note
/// calls the row "the seam read one layer out: an id over an id stores, resolving to whichever
/// member the chain grounds in" — so that a `#[derive(ingraph::Id)]` wrapper over ANOTHER
/// `#[derive(ingraph::Id)]` wrapper needs no row of its own. A wrapper over a
/// `#[derive(ingraph::NewType)]` value used to be the one gap that note named directly: "That
/// device is deliberately not touched here". This row is that gap closed, mirrored rather than
/// reinvented — same shape, same `#inner: IdColumn<Db>` obligation, same bare delegation through
/// `to_stored`/`from_stored`.
///
/// # Stored form follows the inner, unconditionally
///
/// `type Stored = <Inner as IdColumn<Db>>::Stored` — a newtype over a `u64` rides the big-endian
/// blob road the 2026-08-30 ruling put `u64` on, with no word at the newtype's own declaration; a
/// newtype over a member still on the text road keeps riding it. The newtype contributes no
/// encoding of its own, exactly as it contributes none to `DelegatesId`.
///
/// # Why the check/parse GATE plays NO part here, when every other read path spends it
///
/// [`cursor`](Self::cursor)'s `read_cursor` and [`storage`](Self::storage)'s dialect `Decode` both
/// route a freshly-read inner through [`gated_read`](Self::gated_read), because those two paths
/// are handed bytes a CLIENT or a hand-edited row could have written, and the module note's own
/// law is that the gate is spent on every path a value ARRIVES on. This row does not, and the
/// reason is `IdColumn`'s OWN contract read closely rather than an oversight: its trait note
/// states the obligation as "the round trip and nothing else… `from_stored` has to recover every
/// value `to_stored` produced… **nothing else is asked**." A newtype's domain check is additional
/// to that contract, not part of it — the same posture `key_delegation` already takes, which
/// constructs no value and asserts no check either.
fn id_column_delegation(&self) -> proc_macro2::TokenStream {
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let id_column = self.framework(&["id"], "IdColumn");
let db = crate::emit::parameter("DB");
let seam = quote!(#id_column<#db>);
let stored = quote!(<#inner as #seam>::Stored);
let built = self.build("e!(__ingraph_inner));
let generics = self.generics_with(&[syn::parse_quote!(#db)], &[self.owes(&seam)]);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #seam for #subject #where_clause {
type Stored = #stored;
type Refusal = <#inner as #seam>::Refusal;
#[inline]
fn to_stored(&self) -> Self::Stored {
<#inner as #seam>::to_stored(&self.#member)
}
#[inline]
fn from_stored(
__ingraph_stored: Self::Stored,
) -> ::core::result::Result<Self, Self::Refusal> {
::core::result::Result::map(
<#inner as #seam>::from_stored(__ingraph_stored),
|__ingraph_inner| #built,
)
}
}
}
}
// ---------------------------------------------------------------------------------------------
// The filter/marker domain
// ---------------------------------------------------------------------------------------------
/// The READING the filter kit is reached through — `<Name>Wire`, and the row that says what one
/// operand of this newtype crosses on.
///
/// # Why a reading and not a MINT
///
/// The element mode mints `<Name>Filter`, because it had to: `impl async_graphql::InputType for
/// TextFilter<Tag>` is `E0117` in a declaring crate. The framework's carrier axis opened the other
/// road — one generic wire face over the MARKER — so a declaring crate reaches
/// `ScalarFilter<Name, NameWire>` whole by writing the reading below, and this device takes that
/// road: one uninhabited enum and one impl where a mint writes a type, an inherent face, an
/// emptiness contract, a lowering map, an operand map and an input object.
///
/// # The ENUM family has no reading, and the absence is the framework's shape
///
/// `EnumFilter<T>` carries no carrier parameter — a closed vocabulary's operands cross as
/// themselves — so `marker(enum)` names the filter directly and mints nothing.
fn reading(&self) -> proc_macro2::TokenStream {
let (Some(family), true) = (self.kits.marker, self.kits.filter) else {
return quote!();
};
let Some(wire) = family_reading(family) else {
return quote!();
};
let vis = &self.vis;
let name = self.reading_name();
let subject = self.subject_type();
let subject_name = &self.subject;
let reading = self.framework(&["graphql"], wire);
let published = self.filter_sdl();
let (impl_generics, _, where_clause) = self.generics.split_for_impl();
let carrier = self.carrier_form();
let (cross, carry) = self.crossing_bodies();
let doc = format!(
" What a filter over [`{subject_name}`] is PUBLISHED as, and what one of its operands crosses \
on.\n\n Uninhabited: a reading is a place to hang a row, never a value. It is this crate's \
own type, which is what puts `{published}` inside the orphan rule rather than outside it."
);
quote! {
#[doc = #doc]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#vis enum #name {}
#[automatically_derived]
impl #impl_generics #reading<#subject> for #name #where_clause {
const NAME: &'static ::core::primitive::str = #published;
type Carrier = #carrier;
type Error = ::core::convert::Infallible;
#[inline]
fn cross(
__ingraph_carrier: Self::Carrier,
) -> ::core::result::Result<#subject, ::core::convert::Infallible> {
#cross
}
#[inline]
fn carry(__ingraph_operand: &#subject) -> Self::Carrier {
#carry
}
}
}
}
/// The three INTERPRETATION rows a field of this newtype resolves through.
///
/// What `to_filter!` writes for a type the framework itself registers, written here for one it
/// cannot see: the family the value is read under, the filter that family carries, and what a
/// `Vec` of it means. The `Vec` reading is the LIST, which is the framework's own default for
/// every element that does not say otherwise — and a field's own word still beats it.
fn markers(&self) -> proc_macro2::TokenStream {
let Some(family) = self.kits.marker else {
return quote!();
};
let subject = self.subject_type();
let marker = self.framework(&["marker"], family_marker(family));
let default_marker = self.framework(&["marker"], "DefaultMarker");
let default_vec_marker = self.framework(&["marker"], "DefaultVecMarker");
let list_marker = self.framework(&["marker"], "ListMarker");
let (impl_generics, _, where_clause) = self.generics.split_for_impl();
let filter = self.filter_row(family);
quote! {
#[automatically_derived]
impl #impl_generics #default_marker for #subject #where_clause {
type Marker = #marker<#subject>;
}
#[automatically_derived]
impl #impl_generics #default_vec_marker for #subject #where_clause {
type Marker = #list_marker<::std::vec::Vec<#subject>, #marker<#subject>>;
}
#filter
}
}
/// The FILTER row: which of the framework's kinds guards a column of this newtype.
fn filter_row(&self, family: ElementFamily) -> proc_macro2::TokenStream {
if !self.kits.filter {
return quote!();
}
let subject = self.subject_type();
let reading = self.framework(&["marker"], family_filter_marker(family));
let kind = self.framework(&["graphql"], family_filter(family));
let (impl_generics, _, where_clause) = self.generics.split_for_impl();
let held = match family_reading(family) {
Some(_) => {
let wire = self.reading_name();
quote!(#kind<#subject, #wire>)
}
None => quote!(#kind<#subject>),
};
quote! {
#[automatically_derived]
impl #impl_generics #reading for #subject #where_clause {
type Filter = #held;
}
}
}
// ---------------------------------------------------------------------------------------------
// The wire domain
// ---------------------------------------------------------------------------------------------
/// The form ONE operand of this newtype crosses on — the fork the whole wire domain turns on.
///
/// A declaration that publishes a SCALAR of its own crosses as ITSELF: the door below is the form,
/// and a second one beside it would be a grammar the schema does not name. One that publishes no
/// scalar crosses as whatever its inner type crosses as — the newtype is transparent on the wire,
/// which is what a pure operand wrapper is FOR.
fn carrier_form(&self) -> proc_macro2::TokenStream {
if self.kits.scalar.is_some() {
return self.subject_type();
}
let inner = &self.inner;
let crossing = self.framework(&["graphql"], "ToGraphqlInput");
quote!(<#inner as #crossing>::Input)
}
/// The two bodies of a crossing at [`carrier_form`](Self::carrier_form) — identity where the type
/// is its own form, delegation where it is not.
fn crossing_bodies(&self) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) {
if self.kits.scalar.is_some() {
return (
quote!(::core::result::Result::Ok(__ingraph_carrier)),
quote!(::core::clone::Clone::clone(__ingraph_operand)),
);
}
let inner = &self.inner;
let member = &self.member;
let crossing = self.framework(&["graphql"], "ToGraphqlInput");
let built = self.build("e!(__ingraph_inner));
(
quote! {
match <#inner as #crossing>::cross(__ingraph_carrier) {
::core::result::Result::Ok(__ingraph_inner) => ::core::result::Result::Ok(#built),
// The inner crossing's refusal, propagated rather than re-worded: a form this type never
// saw was refused by the type that owns the form, and a second sentence here would
// describe a grammar this device does not have.
::core::result::Result::Err(__ingraph_refused) => {
::core::result::Result::Err(__ingraph_refused)
}
}
},
quote!(<#inner as #crossing>::carry(&__ingraph_operand.#member)),
)
}
/// The two CROSSINGS — what an operand of this newtype looks like on the way in, and what a wire
/// face returns it as on the way out.
///
/// UNGATED, both of them, because the traits are: a crossing says which FORM an operand takes and
/// asks nothing about who parses that form. The face that spends it rides the binding gate; this
/// pair is a fact about the type.
fn crossings(&self) -> proc_macro2::TokenStream {
let input = self.input_crossing();
let output = self.output_crossing();
quote! {
#input
#output
}
}
/// [`ToGraphqlInput`] — the identity where a scalar was declared, the inner's own form where none
/// was.
fn input_crossing(&self) -> proc_macro2::TokenStream {
if !self.kits.input {
return quote!();
}
let subject = self.subject_type();
let inner = &self.inner;
let crossing = self.framework(&["graphql"], "ToGraphqlInput");
let carrier = self.carrier_form();
let (cross, carry) = self.crossing_bodies();
let (error, predicates): (proc_macro2::TokenStream, Vec<syn::WherePredicate>) =
if self.kits.scalar.is_some() {
(quote!(::core::convert::Infallible), Vec::new())
} else {
(
quote!(<#inner as #crossing>::Error),
vec![self.owes(&crossing)],
)
};
let generics = self.generics_with(&[], &predicates);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #crossing for #subject #where_clause {
type Input = #carrier;
type Error = #error;
#[inline]
fn cross(
__ingraph_carrier: Self::Input,
) -> ::core::result::Result<Self, Self::Error> {
#cross
}
#[inline]
fn carry(__ingraph_operand: &Self) -> Self::Input {
#carry
}
}
}
}
/// [`ToGraphqlOutput`] — by REFERENCE where a scalar was declared, and the inner's own output form
/// where none was.
fn output_crossing(&self) -> proc_macro2::TokenStream {
if !self.kits.output {
return quote!();
}
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let crossing = self.framework(&["graphql"], "ToGraphqlOutput");
if self.kits.scalar.is_some() {
let (impl_generics, _, where_clause) = self.generics.split_for_impl();
return quote! {
#[automatically_derived]
impl #impl_generics #crossing for #subject #where_clause {
type Output<'__ingraph>
= &'__ingraph Self
where
Self: '__ingraph;
#[inline]
fn to_graphql_output(__ingraph_value: &Self) -> &Self {
__ingraph_value
}
}
};
}
let generics = self.generics_with(&[], &[self.owes(&crossing)]);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #crossing for #subject #where_clause {
type Output<'__ingraph>
= <#inner as #crossing>::Output<'__ingraph>
where
Self: '__ingraph;
#[inline]
fn to_graphql_output(__ingraph_value: &Self) -> Self::Output<'_> {
<#inner as #crossing>::to_graphql_output(&__ingraph_value.#member)
}
}
}
}
/// The newtype's own SCALAR — the half only a declaring crate can write.
///
/// async-graphql's own attribute over an `impl ScalarType`, which is the shape a declaring crate
/// wrote by hand before this door existed. Spending the library's macro rather than writing the
/// two faces out settles the OUTPUT leg's `boxed-trait` question by not asking it, and keeps the
/// registry entry the library's own.
///
/// # The three bodies, and which of them the GATE moves
///
/// `parse` and `is_valid` share ONE notion of validity, which is the corpus's standing rule: a
/// scalar narrowing in `parse` alone ships a validator admitting what its own parser rejects, and
/// the refusal then lands at execution rather than at validation, where a client is looking.
/// `to_value` is the WRITE, and a write has nothing to check.
fn scalar(&self) -> proc_macro2::TokenStream {
let Some(scalar) = self.kits.scalar.as_ref() else {
return quote!();
};
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let ag = self.framework(&[], "async_graphql");
let gate = self.framework(&["gate"], "if_async_graphql");
let shelf = self.vendored("async_graphql");
let sdl = self.sdl();
let build = self.build("e!(__ingraph_inner));
// THE OBLIGATION, on the impl rather than at the call. A text door renders through `Display`
// and the other two legs read through the carrier's own `InputType`, and stating each as a
// `where` predicate is what lands the refusal at the DECLARATION naming the type that owes it
// — where a bare call would report a missing method inside an expansion, and would not compile
// at all for a wrapped type that is a PARAMETER.
let obligation: syn::WherePredicate = match scalar.gate.as_ref() {
Some(Gate::Parse(_)) => {
let subject_type = self.subject_type();
syn::parse_quote!(#subject_type: ::core::fmt::Display)
}
Some(Gate::Check(_)) | None => {
let bound = quote!(#ag::InputType);
self.owes(&bound)
}
};
let generics = self.generics_with(&[], &[obligation]);
let (impl_generics, _, where_clause) = generics.split_for_impl();
let (parse, valid, render) = match scalar.gate.as_ref() {
// TEXT IN, WIDE: a JSON string, handed to the declaration's own door. What spellings are
// admitted is that function's business and there is no second grammar here to keep in step;
// what this layer adds is the JSON SHAPE, and the refusal a client gets for anything else.
Some(Gate::Parse(door)) => (
quote! {
match &__ingraph_value {
#ag::Value::String(__ingraph_text) => ::core::result::Result::map_err(
#door(__ingraph_text),
#ag::InputValueError::custom,
),
_ => ::core::result::Result::Err(
#ag::InputValueError::expected_type(::core::clone::Clone::clone(&__ingraph_value)),
),
}
},
quote! {
match __ingraph_value {
#ag::Value::String(__ingraph_text) => ::core::result::Result::is_ok(&#door(__ingraph_text)),
_ => false,
}
},
// STRICT OUT: the canonical rendering, whichever spelling came in. `Display` is where a
// text door's canonical form lives — the door folds, so the value this holds is already the
// one spelling this type admits back.
quote!(#ag::Value::String(::std::string::ToString::to_string(self))),
),
// THE CARRIER'S OWN FORM, ANCHORED: the inner type reads the JSON — a number is a number — and
// the door says whether the value it read is one of this type's.
Some(Gate::Check(door)) => (
quote! {
match <#inner as #ag::InputType>::parse(::core::option::Option::Some(
::core::clone::Clone::clone(&__ingraph_value),
)) {
::core::result::Result::Ok(__ingraph_inner) => ::core::result::Result::map_err(
#door(__ingraph_inner),
#ag::InputValueError::custom,
),
::core::result::Result::Err(__ingraph_refused) => ::core::result::Result::Err(
#ag::InputValueError::propagate(__ingraph_refused),
),
}
},
quote! {
match <#inner as #ag::InputType>::parse(::core::option::Option::Some(
::core::clone::Clone::clone(__ingraph_value),
)) {
::core::result::Result::Ok(__ingraph_inner) => {
::core::result::Result::is_ok(&#door(__ingraph_inner))
}
::core::result::Result::Err(_) => false,
}
},
quote!(<#inner as #ag::InputType>::to_value(&self.#member)),
),
// NO DOOR: the wire grammar is the INNER type's, under this type's name. An inner type with no
// wire face of its own is `E0277` naming that type.
None => (
quote! {
::core::result::Result::map_err(
::core::result::Result::map(
<#inner as #ag::InputType>::parse(::core::option::Option::Some(__ingraph_value)),
|__ingraph_inner| #build,
),
#ag::InputValueError::propagate,
)
},
quote! {
::core::result::Result::is_ok(&<#inner as #ag::InputType>::parse(
::core::option::Option::Some(::core::clone::Clone::clone(__ingraph_value)),
))
},
quote!(<#inner as #ag::InputType>::to_value(&self.#member)),
),
};
quote! {
#gate! {
#[#ag::Scalar(crate = #shelf, name = #sdl)]
impl #impl_generics #ag::ScalarType for #subject #where_clause {
fn parse(__ingraph_value: #ag::Value) -> #ag::InputValueResult<Self> {
#parse
}
fn is_valid(__ingraph_value: &#ag::Value) -> ::core::primitive::bool {
#valid
}
fn to_value(&self) -> #ag::Value {
#render
}
}
}
}
}
// ---------------------------------------------------------------------------------------------
// The page and storage domains
// ---------------------------------------------------------------------------------------------
/// [`CursorValue`] — the keyset position, WRITTEN as the inner type writes it and READ back
/// through this type's own door.
///
/// The read RE-VALIDATES wherever a door was declared, and that is not belt and braces: a cursor
/// is a string a CLIENT hands back, so a forged position is refused rather than turned into a
/// value whose type says it cannot exist. Where no door was declared there is no invariant to
/// keep, and the inner's own `read_cursor` is the whole check — its width, its charset and its
/// domain.
fn cursor(&self) -> proc_macro2::TokenStream {
if !self.kits.cursor {
return quote!();
}
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let cursor_value = self.framework(&["cursor"], "CursorValue");
let read = self.gated_read("e!(__ingraph_inner), ReadFailure::None);
let mut predicates = vec![self.owes(&cursor_value)];
predicates.extend(self.rendering());
let generics = self.generics_with(&[], &predicates);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #cursor_value for #subject #where_clause {
#[inline]
fn write_cursor(&self, __ingraph_out: &mut ::std::vec::Vec<::core::primitive::u8>) {
<#inner as #cursor_value>::write_cursor(&self.#member, __ingraph_out)
}
fn read_cursor(
__ingraph_bytes: &[::core::primitive::u8],
) -> ::core::option::Option<Self> {
match <#inner as #cursor_value>::read_cursor(__ingraph_bytes) {
::core::option::Option::Some(__ingraph_inner) => #read,
::core::option::Option::None => ::core::option::Option::None,
}
}
}
}
}
/// [`ColumnKind`] — what this newtype spans beneath the field that names it.
///
/// The inner type's answer, which is the whole content of a transparent wrapper's width: a
/// newtype over a `u64` is one column and a newtype over a two-column composite is two, and
/// nothing here decides which.
///
/// UNGATED, as the trait is: a width names no database. It is emitted wherever a DIALECT was named
/// — that being the one place the fact is spent — and a declaration that names none has no column
/// to have a width.
///
/// The SAMENESS row beside it is emitted UNCONDITIONALLY, and the asymmetry is where each is
/// spent: a width is read by a row, and a row exists only where a dialect was named, but a
/// `ColumnEq` is folded by a PAGE CURSOR too — and by the `#[derive(ingraph::Id)]` wrapper this
/// value may be the inner of, which names its own databases rather than inheriting these. That is
/// the posture `id`'s device already takes for the same reason, and the row costs a declaration
/// nothing it does not already owe: its obligation is the INNER's `ColumnEq`, stated in a `where`
/// clause and therefore proved only where something actually compares one.
fn column(&self) -> proc_macro2::TokenStream {
let subject = self.subject_type();
let inner = &self.inner;
let column_eq = self.framework(&["column"], "ColumnEq");
let eq_generics = self.generics_with(&[], &[self.owes(&column_eq)]);
let (eq_impl_generics, _, eq_where_clause) = eq_generics.split_for_impl();
// The SAMENESS row, on the width row's own argument read one face over: a transparent wrapper
// IS the value it wraps, so two of them are one column value exactly when the two inners are. It
// owes the inner's `ColumnEq` rather than a `PartialEq`, which is what lets a newtype over a
// type whose sameness is not `==` be stored without this device knowing which type that is.
let sameness = quote! {
#[automatically_derived]
impl #eq_impl_generics #column_eq for #subject #eq_where_clause {
#[inline]
fn column_eq(&self, __ingraph_other: &Self) -> ::core::primitive::bool {
<#inner as #column_eq>::column_eq(&self.0, &__ingraph_other.0)
}
}
};
if self.kits.databases.is_empty() {
return sameness;
}
let column_kind = self.framework(&["column"], "ColumnKind");
let shape = self.framework(&["column"], "ColumnShape");
let generics = self.generics_with(&[], &[self.owes(&column_kind)]);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #column_kind for #subject #where_clause {
const SEGMENTS: &'static [#shape] = <#inner as #column_kind>::SEGMENTS;
}
#sameness
}
}
/// [`StoredAs`] — the WORD a dialect's `CREATE TABLE` declares this newtype's columns with.
///
/// [`column`](Self::column)'s twin, one face over and by the same argument: a transparent wrapper
/// is declared exactly as the thing it wraps, so a newtype over a `u64` takes `BIGINT` where that
/// `u64` does and one over a composite takes its whole list. Nothing here chooses a word.
///
/// ONE impl over every dialect at once, for the reason `ColumnKind`'s is one impl over every
/// width: the parameter is the trait's, the inner type's obligation is stated at it, and a dialect
/// the inner type has no row in is `E0277` naming that type at the call site that asked. `Db`
/// carries no bound here because the trait carries none — a downstream target that is no
/// `sqlx::Database` joins by writing rows, and a wrapper over a type that joined must follow.
fn stored(&self) -> proc_macro2::TokenStream {
if self.kits.databases.is_empty() {
return quote!();
}
let subject = self.subject_type();
let inner = &self.inner;
let stored_as = self.framework(&["column"], "StoredAs");
let db = crate::emit::parameter("DB");
let generics = self.generics_with(
&[syn::parse_quote!(#db)],
&[self.owes("e!(#stored_as<#db>))],
);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#[automatically_derived]
impl #impl_generics #stored_as<#db> for #subject #where_clause {
const WORDS: &'static [&'static ::core::primitive::str] =
<#inner as #stored_as<#db>>::WORDS;
}
}
}
/// [`Assemble`] — how a holder's row reads one of these back.
///
/// Generic over the ROW and stated ONCE, where the bind rows are per dialect: what varies per
/// dialect is the `Decode` this delegates through, and stating it as an obligation on the INNER
/// type is what lets one impl serve every dialect the declaration's own rows cover.
///
/// The FAMILY gate rather than a dialect's, and rather than none: the trait is `sqlx::Row`'s
/// vocabulary, so a build with no SQL family has no trait for this to implement — while a build
/// with two would get this impl twice if it rode the per-dialect gates the bind rows ride.
fn read(&self) -> proc_macro2::TokenStream {
if self.kits.databases.is_empty() {
return quote!();
}
let subject = self.subject_type();
let inner = &self.inner;
let gate = self.framework(&["gate"], "if_sqlx");
let assemble = self.framework(&["column"], "Assemble");
let path = self.framework(&["comparison"], "Path");
let result = self.framework(&["sqlx"], "Result");
let row = crate::emit::parameter("ROW");
let bound = quote!(#assemble<'__ingraph, #row>);
let read = self.gated_read("e!(__ingraph_inner), ReadFailure::Decode);
let mut predicates = vec![self.owes(&bound)];
predicates.extend(self.rendering());
let generics = self.generics_with(
&[
syn::parse_quote!('__ingraph),
syn::GenericParam::Type(syn::TypeParam::from(row.clone())),
],
&predicates,
);
let (impl_generics, _, where_clause) = generics.split_for_impl();
quote! {
#gate! {
#[automatically_derived]
impl #impl_generics #assemble<'__ingraph, #row> for #subject #where_clause {
fn assemble(
__ingraph_row: &'__ingraph #row,
__ingraph_under: ::core::option::Option<&#path<'_>>,
) -> #result<Self> {
let __ingraph_inner =
<#inner as #bound>::assemble(__ingraph_row, __ingraph_under)?;
#read
}
}
}
}
}
/// ONE dialect's rows: the three sqlx halves and the framework's own bind.
///
/// All four DELEGATE, and `Encode` delegates in FULL — `encode`, `encode_by_ref`, `produces` and
/// `size_hint`. [`produces`](sqlx::Encode::produces) is the one that would matter quietly: it is
/// the per-VALUE type override, consulted ahead of `Type::type_info`, so a default `None` here
/// would discard an inner type's answer with nothing to see.
fn storage(&self, database: DatabaseKind) -> proc_macro2::TokenStream {
let subject = self.subject_type();
let inner = &self.inner;
let member = &self.member;
let gate = self.framework(&["gate"], &database.gate().to_string());
let (segments, item) = database.backend();
let backend = self.framework(segments, item);
let carrier = self.framework(&["comparison", "sql"], "Carrier");
let query_builder = self.framework(&["sqlx"], "QueryBuilder");
let sqlx_type = self.framework(&["sqlx"], "Type");
let encode = self.framework(&["sqlx"], "Encode");
let decode = self.framework(&["sqlx"], "Decode");
let database_trait = self.framework(&["sqlx"], "Database");
let is_null = self.framework(&["sqlx", "encode"], "IsNull");
let error = self.framework(&["sqlx", "error"], "BoxDynError");
let type_bound = quote!(#sqlx_type<#backend>);
let type_generics = self.generics_with(&[], &[self.owes(&type_bound)]);
let (type_impl, _, type_where) = type_generics.split_for_impl();
let encode_bound = quote!(#encode<'__ingraph, #backend>);
let encode_generics = self.generics_with(
&[syn::parse_quote!('__ingraph)],
&[self.owes(&encode_bound)],
);
let (encode_impl, _, encode_where) = encode_generics.split_for_impl();
let decode_bound = quote!(#decode<'__ingraph, #backend>);
let mut decode_predicates = vec![self.owes(&decode_bound)];
decode_predicates.extend(self.rendering());
let decode_generics = self.generics_with(&[syn::parse_quote!('__ingraph)], &decode_predicates);
let (decode_impl, _, decode_where) = decode_generics.split_for_impl();
let decoded = self.gated_read("e!(__ingraph_inner), ReadFailure::Boxed);
let carrier_bound = quote!(#carrier<#backend>);
let carrier_generics = self.generics_with(&[], &[self.owes(&carrier_bound)]);
let (carrier_impl, _, carrier_where) = carrier_generics.split_for_impl();
let taken = match &self.member {
syn::Member::Named(ident) => quote!(self.#ident),
syn::Member::Unnamed(index) => quote!(self.#index),
};
quote! {
#gate! {
#[automatically_derived]
impl #type_impl #sqlx_type<#backend> for #subject #type_where {
fn type_info() -> <#backend as #database_trait>::TypeInfo {
<#inner as #type_bound>::type_info()
}
fn compatible(
__ingraph_info: &<#backend as #database_trait>::TypeInfo,
) -> ::core::primitive::bool {
<#inner as #type_bound>::compatible(__ingraph_info)
}
}
#[automatically_derived]
impl #encode_impl #encode<'__ingraph, #backend> for #subject #encode_where {
fn encode(
self,
__ingraph_buf: &mut <#backend as #database_trait>::ArgumentBuffer,
) -> ::core::result::Result<#is_null, #error> {
<#inner as #encode_bound>::encode(#taken, __ingraph_buf)
}
fn encode_by_ref(
&self,
__ingraph_buf: &mut <#backend as #database_trait>::ArgumentBuffer,
) -> ::core::result::Result<#is_null, #error> {
<#inner as #encode_bound>::encode_by_ref(&self.#member, __ingraph_buf)
}
fn produces(
&self,
) -> ::core::option::Option<<#backend as #database_trait>::TypeInfo> {
<#inner as #encode_bound>::produces(&self.#member)
}
fn size_hint(&self) -> ::core::primitive::usize {
<#inner as #encode_bound>::size_hint(&self.#member)
}
}
#[automatically_derived]
impl #decode_impl #decode<'__ingraph, #backend> for #subject #decode_where {
fn decode(
__ingraph_value: <#backend as #database_trait>::ValueRef<'__ingraph>,
) -> ::core::result::Result<Self, #error> {
let __ingraph_inner = <#inner as #decode_bound>::decode(__ingraph_value)?;
#decoded
}
}
#[automatically_derived]
impl #carrier_impl #carrier<#backend> for #subject #carrier_where {
fn push_bind(&self, __ingraph_qb: &mut #query_builder<#backend>) {
<#inner as #carrier_bound>::push_bind(&self.#member, __ingraph_qb)
}
}
}
}
}
/// One READ path's tail: the door where one was declared, the plain wrap where none was.
///
/// `failure` is what a refused door becomes at that position, which is the only thing the three
/// read paths differ in — a cursor answers [`None`], a decode answers its own error type. The
/// DOOR is the same door at all three, which is the whole of *one source*.
fn gated_read(
&self,
inner: &proc_macro2::TokenStream,
failure: ReadFailure,
) -> proc_macro2::TokenStream {
let built = self.build(inner);
let Some(gate) = self.kits.gate() else {
return match failure {
ReadFailure::None => quote!(::core::option::Option::Some(#built)),
ReadFailure::Decode | ReadFailure::Boxed => quote!(::core::result::Result::Ok(#built)),
};
};
let call = match gate {
// A text door reads SPELLINGS, and a stored value or a cursor's bytes have already been read
// back as the inner type — so the door is reached through that type's own text form, which is
// the one rendering `to_value` wrote out.
Gate::Parse(door) => {
let text = quote!(::std::string::ToString::to_string(&#inner));
quote!(#door(&#text))
}
Gate::Check(door) => quote!(#door(#inner)),
};
match failure {
ReadFailure::None => quote! {
match #call {
::core::result::Result::Ok(__ingraph_value) => ::core::option::Option::Some(__ingraph_value),
::core::result::Result::Err(_) => ::core::option::Option::None,
}
},
ReadFailure::Decode => {
let sqlx_error = self.framework(&["sqlx"], "Error");
quote! {
match #call {
::core::result::Result::Ok(__ingraph_value) => ::core::result::Result::Ok(__ingraph_value),
::core::result::Result::Err(__ingraph_refused) => ::core::result::Result::Err(
#sqlx_error::Decode(::std::boxed::Box::new(__ingraph_refused)),
),
}
}
}
ReadFailure::Boxed => quote! {
match #call {
::core::result::Result::Ok(__ingraph_value) => ::core::result::Result::Ok(__ingraph_value),
::core::result::Result::Err(__ingraph_refused) => {
::core::result::Result::Err(::std::convert::From::from(__ingraph_refused))
}
}
},
}
}
}
/// What a refused door becomes at ONE read position.
#[derive(Clone, Copy)]
enum ReadFailure {
/// A cursor: a forged position is [`None`], and there is no sentence to carry.
None,
/// A row decode: `sqlx::Error::Decode`, carrying the door's own refusal.
Decode,
/// A value decode: `sqlx::error::BoxDynError`, reached through `From`.
Boxed,
}
/// The marker one family is spelled as, which a field of the newtype resolves to by default.
const fn family_marker(family: ElementFamily) -> &'static str {
match family {
ElementFamily::Scalar => "ScalarMarker",
ElementFamily::String => "StringMarker",
ElementFamily::Bytes => "BytesMarker",
ElementFamily::Enum => "EnumMarker",
}
}
/// The family trait that carries this family's filter — the map a field's reading resolves through.
const fn family_filter_marker(family: ElementFamily) -> &'static str {
match family {
ElementFamily::Scalar => "ScalarFilterMarker",
ElementFamily::String => "StringFilterMarker",
ElementFamily::Bytes => "BytesFilterMarker",
ElementFamily::Enum => "EnumFilterMarker",
}
}
/// The framework filter one family's reading names.
const fn family_filter(family: ElementFamily) -> &'static str {
match family {
ElementFamily::Scalar => "ScalarFilter",
ElementFamily::String => "TextFilter",
ElementFamily::Bytes => "BytesFilter",
ElementFamily::Enum => "EnumFilter",
}
}
/// The CARRIER READING one family is reached through, where it has one.
///
/// The enumeration has none, and the absence is the framework's shape rather than a gap:
/// `EnumFilter<T>` takes no carrier parameter, a closed vocabulary's operands crossing as
/// themselves — so `marker(enum)` names the filter directly and there is no reading to mint.
const fn family_reading(family: ElementFamily) -> Option<&'static str> {
match family {
ElementFamily::Scalar => Some("ScalarWire"),
ElementFamily::String => Some("TextWire"),
ElementFamily::Bytes => Some("BytesWire"),
ElementFamily::Enum => None,
}
}