uor-foundation 0.4.11

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

//! `carry/` namespace — Carry chain algebra: generate/propagate/kill event classification, carry profiles, encoding configurations, and encoding quality metrics for d_Δ optimization..
//!
//! Space: Kernel

use crate::enums::MeasurementUnit;
use crate::HostTypes;

/// The Boolean function chain c_{k+1} = or(and(x_k, y_k), and(xor(x_k, y_k), c_k)). The carry chain is the algebraic mechanism behind the incompatibility metric d_Δ.
pub trait CarryChain<H: HostTypes> {
    /// The number of sites in this carry chain.
    fn chain_length(&self) -> u64;
    /// Bit mask of site positions where carry is generated: and(x_k, y_k) = 1.
    fn generate_mask(&self) -> u64;
    /// Bit mask of site positions where carry propagates: xor(x_k, y_k) = 1.
    fn propagate_mask(&self) -> u64;
    /// Bit mask of site positions where carry is killed: neither generated nor propagated.
    fn kill_mask(&self) -> u64;
}

/// A single carry event at site k. Three kinds: Generate (and(x_k, y_k) = 1), Propagate (xor(x_k, y_k) = 1 and c_k = 1), Kill (neither generate nor propagate).
pub trait CarryEvent<H: HostTypes> {
    /// The kind of carry event: Generate, Propagate, or Kill.
    fn event_kind(&self) -> u64;
    /// The site index k at which this carry event occurs.
    fn site_position(&self) -> u64;
}

/// The complete carry pattern for an addition x + y. Aggregates carry events across all sites into counts and position masks.
pub trait CarryProfile<H: HostTypes> {
    /// The total number of carry events in this profile.
    fn carry_count(&self) -> u64;
    /// The longest consecutive propagation run in this profile.
    fn max_propagation_length(&self) -> u64;
    /// Associated type for `CarryChain`.
    type CarryChain: CarryChain<H>;
    /// The carry chain that this profile summarizes.
    fn profile_chain(&self) -> &Self::CarryChain;
}

/// A mapping from a finite symbol set S to Z/(2^k)Z where 2^k ≥ |S|. Determines how domain values are represented as ring elements.
pub trait EncodingConfiguration<H: HostTypes> {
    /// The cardinality of the symbol set S being encoded.
    fn symbol_set_size(&self) -> u64;
    /// The number of bits k used for encoding (2^k ≥ |S|).
    fn quantization_bits(&self) -> u64;
    /// Associated type for `TermExpression`.
    type TermExpression: crate::kernel::schema::TermExpression<H>;
    /// String representation of the mapping from symbols to ring elements.
    fn encoding_map(&self) -> &Self::TermExpression;
}

/// The d_Δ quality metric for an encoding over observed data. Measures how well an encoding minimizes carry-induced metric incompatibility.
pub trait EncodingQuality<H: HostTypes> {
    /// The mean d_Δ over observed pairs for this encoding.
    fn mean_delta(&self) -> H::Decimal;
    /// The ratio of distinguishable pairs to total pairs under this encoding.
    fn discrimination_ratio(&self) -> H::Decimal;
    /// Whether this encoding minimizes Σ d_Δ over observed pairs.
    fn is_optimal_encoding(&self) -> bool;
}

/// Observes the carry depth of a Datum in the W₂ tower, computed as the maximum carry-chain length in any operation producing it. Used as the bound observable for the carryConstraintKind BoundConstraint.
pub trait CarryDepthObservable<H: HostTypes>: crate::bridge::observable::Observable<H> {}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `CarryChain<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullCarryChain<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullCarryChain<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullCarryChain<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullCarryChain<H> = NullCarryChain {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> CarryChain<H> for NullCarryChain<H> {
    fn chain_length(&self) -> u64 {
        0
    }
    fn generate_mask(&self) -> u64 {
        0
    }
    fn propagate_mask(&self) -> u64 {
        0
    }
    fn kill_mask(&self) -> u64 {
        0
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `CarryEvent<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullCarryEvent<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullCarryEvent<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullCarryEvent<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullCarryEvent<H> = NullCarryEvent {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> CarryEvent<H> for NullCarryEvent<H> {
    fn event_kind(&self) -> u64 {
        0
    }
    fn site_position(&self) -> u64 {
        0
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `CarryProfile<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullCarryProfile<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullCarryProfile<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullCarryProfile<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullCarryProfile<H> = NullCarryProfile {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> CarryProfile<H> for NullCarryProfile<H> {
    fn carry_count(&self) -> u64 {
        0
    }
    fn max_propagation_length(&self) -> u64 {
        0
    }
    type CarryChain = NullCarryChain<H>;
    fn profile_chain(&self) -> &Self::CarryChain {
        &<NullCarryChain<H>>::ABSENT
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `EncodingConfiguration<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullEncodingConfiguration<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullEncodingConfiguration<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullEncodingConfiguration<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullEncodingConfiguration<H> = NullEncodingConfiguration {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> EncodingConfiguration<H> for NullEncodingConfiguration<H> {
    fn symbol_set_size(&self) -> u64 {
        0
    }
    fn quantization_bits(&self) -> u64 {
        0
    }
    type TermExpression = crate::kernel::schema::NullTermExpression<H>;
    fn encoding_map(&self) -> &Self::TermExpression {
        &<crate::kernel::schema::NullTermExpression<H>>::ABSENT
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `EncodingQuality<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullEncodingQuality<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullEncodingQuality<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullEncodingQuality<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullEncodingQuality<H> = NullEncodingQuality {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> EncodingQuality<H> for NullEncodingQuality<H> {
    fn mean_delta(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn discrimination_ratio(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn is_optimal_encoding(&self) -> bool {
        false
    }
}

/// Phase 2 (orphan-closure) — resolver-absent default impl of `CarryDepthObservable<H>`.
/// Every accessor returns `H::EMPTY_*` sentinels (for scalar / host-typed
/// returns) or a `'static`-lifetime reference to a sibling `Null*`'s `ABSENT`
/// const (for trait-typed returns).  Downstream provides concrete impls;
/// this stub closes the ontology-derived trait orphan.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NullCarryDepthObservable<H: HostTypes> {
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Default for NullCarryDepthObservable<H> {
    fn default() -> Self {
        Self {
            _phantom: core::marker::PhantomData,
        }
    }
}
impl<H: HostTypes> NullCarryDepthObservable<H> {
    /// Absent-value sentinel. `&Self::ABSENT` gives every trait-typed accessor a `'static`-lifetime reference target.
    pub const ABSENT: NullCarryDepthObservable<H> = NullCarryDepthObservable {
        _phantom: core::marker::PhantomData,
    };
}
impl<H: HostTypes> crate::bridge::observable::Observable<H> for NullCarryDepthObservable<H> {
    fn value(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn source(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn target(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn has_unit(&self) -> MeasurementUnit {
        <MeasurementUnit>::default()
    }
}
impl<H: HostTypes> CarryDepthObservable<H> for NullCarryDepthObservable<H> {}

/// Phase 8 (orphan-closure) — content-addressed handle for `CarryChain<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct CarryChainHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for CarryChainHandle<H> {}
impl<H: HostTypes> Clone for CarryChainHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for CarryChainHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for CarryChainHandle<H> {}
impl<H: HostTypes> core::hash::Hash for CarryChainHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> CarryChainHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `CarryChain<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait CarryChainResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: CarryChainHandle<H>) -> Option<CarryChainRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `CarryChain<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CarryChainRecord<H: HostTypes> {
    pub chain_length: u64,
    pub generate_mask: u64,
    pub propagate_mask: u64,
    pub kill_mask: u64,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `CarryChain<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedCarryChain<'r, R: CarryChainResolver<H>, H: HostTypes> {
    handle: CarryChainHandle<H>,
    resolver: &'r R,
    record: Option<CarryChainRecord<H>>,
}
impl<'r, R: CarryChainResolver<H>, H: HostTypes> ResolvedCarryChain<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: CarryChainHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> CarryChainHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&CarryChainRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: CarryChainResolver<H>, H: HostTypes> CarryChain<H> for ResolvedCarryChain<'r, R, H> {
    fn chain_length(&self) -> u64 {
        match &self.record {
            Some(r) => r.chain_length,
            None => 0,
        }
    }
    fn generate_mask(&self) -> u64 {
        match &self.record {
            Some(r) => r.generate_mask,
            None => 0,
        }
    }
    fn propagate_mask(&self) -> u64 {
        match &self.record {
            Some(r) => r.propagate_mask,
            None => 0,
        }
    }
    fn kill_mask(&self) -> u64 {
        match &self.record {
            Some(r) => r.kill_mask,
            None => 0,
        }
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `CarryEvent<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct CarryEventHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for CarryEventHandle<H> {}
impl<H: HostTypes> Clone for CarryEventHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for CarryEventHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for CarryEventHandle<H> {}
impl<H: HostTypes> core::hash::Hash for CarryEventHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> CarryEventHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `CarryEvent<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait CarryEventResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: CarryEventHandle<H>) -> Option<CarryEventRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `CarryEvent<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CarryEventRecord<H: HostTypes> {
    pub event_kind: u64,
    pub site_position: u64,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `CarryEvent<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedCarryEvent<'r, R: CarryEventResolver<H>, H: HostTypes> {
    handle: CarryEventHandle<H>,
    resolver: &'r R,
    record: Option<CarryEventRecord<H>>,
}
impl<'r, R: CarryEventResolver<H>, H: HostTypes> ResolvedCarryEvent<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: CarryEventHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> CarryEventHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&CarryEventRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: CarryEventResolver<H>, H: HostTypes> CarryEvent<H> for ResolvedCarryEvent<'r, R, H> {
    fn event_kind(&self) -> u64 {
        match &self.record {
            Some(r) => r.event_kind,
            None => 0,
        }
    }
    fn site_position(&self) -> u64 {
        match &self.record {
            Some(r) => r.site_position,
            None => 0,
        }
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `CarryProfile<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct CarryProfileHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for CarryProfileHandle<H> {}
impl<H: HostTypes> Clone for CarryProfileHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for CarryProfileHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for CarryProfileHandle<H> {}
impl<H: HostTypes> core::hash::Hash for CarryProfileHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> CarryProfileHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `CarryProfile<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait CarryProfileResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: CarryProfileHandle<H>) -> Option<CarryProfileRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `CarryProfile<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CarryProfileRecord<H: HostTypes> {
    pub carry_count: u64,
    pub max_propagation_length: u64,
    pub profile_chain_handle: CarryChainHandle<H>,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `CarryProfile<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedCarryProfile<'r, R: CarryProfileResolver<H>, H: HostTypes> {
    handle: CarryProfileHandle<H>,
    resolver: &'r R,
    record: Option<CarryProfileRecord<H>>,
}
impl<'r, R: CarryProfileResolver<H>, H: HostTypes> ResolvedCarryProfile<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: CarryProfileHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> CarryProfileHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&CarryProfileRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: CarryProfileResolver<H>, H: HostTypes> CarryProfile<H>
    for ResolvedCarryProfile<'r, R, H>
{
    fn carry_count(&self) -> u64 {
        match &self.record {
            Some(r) => r.carry_count,
            None => 0,
        }
    }
    fn max_propagation_length(&self) -> u64 {
        match &self.record {
            Some(r) => r.max_propagation_length,
            None => 0,
        }
    }
    type CarryChain = NullCarryChain<H>;
    fn profile_chain(&self) -> &Self::CarryChain {
        &<NullCarryChain<H>>::ABSENT
    }
}
impl<'r, R: CarryProfileResolver<H>, H: HostTypes> ResolvedCarryProfile<'r, R, H> {
    /// Promote the `profile_chain` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_profile_chain<'r2, R2: CarryChainResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<ResolvedCarryChain<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(ResolvedCarryChain::new(record.profile_chain_handle, r))
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `EncodingConfiguration<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct EncodingConfigurationHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for EncodingConfigurationHandle<H> {}
impl<H: HostTypes> Clone for EncodingConfigurationHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for EncodingConfigurationHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for EncodingConfigurationHandle<H> {}
impl<H: HostTypes> core::hash::Hash for EncodingConfigurationHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> EncodingConfigurationHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `EncodingConfiguration<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait EncodingConfigurationResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(
        &self,
        handle: EncodingConfigurationHandle<H>,
    ) -> Option<EncodingConfigurationRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `EncodingConfiguration<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct EncodingConfigurationRecord<H: HostTypes> {
    pub symbol_set_size: u64,
    pub quantization_bits: u64,
    pub encoding_map_handle: crate::kernel::schema::TermExpressionHandle<H>,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `EncodingConfiguration<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedEncodingConfiguration<'r, R: EncodingConfigurationResolver<H>, H: HostTypes> {
    handle: EncodingConfigurationHandle<H>,
    resolver: &'r R,
    record: Option<EncodingConfigurationRecord<H>>,
}
impl<'r, R: EncodingConfigurationResolver<H>, H: HostTypes>
    ResolvedEncodingConfiguration<'r, R, H>
{
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: EncodingConfigurationHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> EncodingConfigurationHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&EncodingConfigurationRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: EncodingConfigurationResolver<H>, H: HostTypes> EncodingConfiguration<H>
    for ResolvedEncodingConfiguration<'r, R, H>
{
    fn symbol_set_size(&self) -> u64 {
        match &self.record {
            Some(r) => r.symbol_set_size,
            None => 0,
        }
    }
    fn quantization_bits(&self) -> u64 {
        match &self.record {
            Some(r) => r.quantization_bits,
            None => 0,
        }
    }
    type TermExpression = crate::kernel::schema::NullTermExpression<H>;
    fn encoding_map(&self) -> &Self::TermExpression {
        &<crate::kernel::schema::NullTermExpression<H>>::ABSENT
    }
}
impl<'r, R: EncodingConfigurationResolver<H>, H: HostTypes>
    ResolvedEncodingConfiguration<'r, R, H>
{
    /// Promote the `encoding_map` handle on the cached record into a
    /// resolved wrapper, given a resolver for the range class.
    /// Returns `None` if no record was resolved at construction.
    #[inline]
    pub fn resolve_encoding_map<'r2, R2: crate::kernel::schema::TermExpressionResolver<H>>(
        &self,
        r: &'r2 R2,
    ) -> Option<crate::kernel::schema::ResolvedTermExpression<'r2, R2, H>> {
        let record = self.record.as_ref()?;
        Some(crate::kernel::schema::ResolvedTermExpression::new(
            record.encoding_map_handle,
            r,
        ))
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `EncodingQuality<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct EncodingQualityHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for EncodingQualityHandle<H> {}
impl<H: HostTypes> Clone for EncodingQualityHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for EncodingQualityHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for EncodingQualityHandle<H> {}
impl<H: HostTypes> core::hash::Hash for EncodingQualityHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> EncodingQualityHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `EncodingQuality<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait EncodingQualityResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(&self, handle: EncodingQualityHandle<H>) -> Option<EncodingQualityRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `EncodingQuality<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct EncodingQualityRecord<H: HostTypes> {
    pub mean_delta: H::Decimal,
    pub discrimination_ratio: H::Decimal,
    pub is_optimal_encoding: bool,
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `EncodingQuality<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedEncodingQuality<'r, R: EncodingQualityResolver<H>, H: HostTypes> {
    handle: EncodingQualityHandle<H>,
    resolver: &'r R,
    record: Option<EncodingQualityRecord<H>>,
}
impl<'r, R: EncodingQualityResolver<H>, H: HostTypes> ResolvedEncodingQuality<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: EncodingQualityHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> EncodingQualityHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&EncodingQualityRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: EncodingQualityResolver<H>, H: HostTypes> EncodingQuality<H>
    for ResolvedEncodingQuality<'r, R, H>
{
    fn mean_delta(&self) -> H::Decimal {
        match &self.record {
            Some(r) => r.mean_delta,
            None => H::EMPTY_DECIMAL,
        }
    }
    fn discrimination_ratio(&self) -> H::Decimal {
        match &self.record {
            Some(r) => r.discrimination_ratio,
            None => H::EMPTY_DECIMAL,
        }
    }
    fn is_optimal_encoding(&self) -> bool {
        match &self.record {
            Some(r) => r.is_optimal_encoding,
            None => false,
        }
    }
}

/// Phase 8 (orphan-closure) — content-addressed handle for `CarryDepthObservable<H>`.
///
/// Pairs a [`crate::enforcement::ContentFingerprint`] with a phantom
/// `H` so type-state checks can't mix handles across `HostTypes` impls.
#[derive(Debug)]
pub struct CarryDepthObservableHandle<H: HostTypes> {
    /// Content fingerprint identifying the resolved record.
    pub fingerprint: crate::enforcement::ContentFingerprint,
    _phantom: core::marker::PhantomData<H>,
}
impl<H: HostTypes> Copy for CarryDepthObservableHandle<H> {}
impl<H: HostTypes> Clone for CarryDepthObservableHandle<H> {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}
impl<H: HostTypes> PartialEq for CarryDepthObservableHandle<H> {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.fingerprint == other.fingerprint
    }
}
impl<H: HostTypes> Eq for CarryDepthObservableHandle<H> {}
impl<H: HostTypes> core::hash::Hash for CarryDepthObservableHandle<H> {
    #[inline]
    fn hash<S: core::hash::Hasher>(&self, state: &mut S) {
        self.fingerprint.hash(state);
    }
}
impl<H: HostTypes> CarryDepthObservableHandle<H> {
    /// Construct a handle from its content fingerprint.
    #[inline]
    #[must_use]
    pub const fn new(fingerprint: crate::enforcement::ContentFingerprint) -> Self {
        Self {
            fingerprint,
            _phantom: core::marker::PhantomData,
        }
    }
}

/// Phase 8 (orphan-closure) — resolver trait for `CarryDepthObservable<H>`.
///
/// Hosts implement this trait to map a handle into a typed record.
/// The default Null stub does not implement this trait — it carries
/// no record. Resolution is the responsibility of the host pipeline.
pub trait CarryDepthObservableResolver<H: HostTypes> {
    /// Resolve a handle into its record. Returns `None` when the
    /// handle does not correspond to known content.
    fn resolve(
        &self,
        handle: CarryDepthObservableHandle<H>,
    ) -> Option<CarryDepthObservableRecord<H>>;
}

/// Phase 8 (orphan-closure) — typed record for `CarryDepthObservable<H>`.
///
/// Carries a field per functional accessor of the trait. Object
/// fields hold `{Range}Handle<H>`; iterate via the Resolved wrapper
/// chain-resolver methods.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CarryDepthObservableRecord<H: HostTypes> {
    #[doc(hidden)]
    pub _phantom: core::marker::PhantomData<H>,
}

/// Phase 8 (orphan-closure) — content-addressed wrapper for `CarryDepthObservable<H>`.
///
/// Caches the resolver's lookup at construction. Accessors return
/// the cached record's fields when present, falling back to the
/// `Null{Class}<H>` absent sentinels when the resolver returned
/// `None`. Object accessors always return absent sentinels — use
/// the `resolve_{m}` chain methods to descend into sub-records.
pub struct ResolvedCarryDepthObservable<'r, R: CarryDepthObservableResolver<H>, H: HostTypes> {
    handle: CarryDepthObservableHandle<H>,
    resolver: &'r R,
    record: Option<CarryDepthObservableRecord<H>>,
}
impl<'r, R: CarryDepthObservableResolver<H>, H: HostTypes> ResolvedCarryDepthObservable<'r, R, H> {
    /// Construct the wrapper, eagerly resolving the handle.
    #[inline]
    pub fn new(handle: CarryDepthObservableHandle<H>, resolver: &'r R) -> Self {
        let record = resolver.resolve(handle);
        Self {
            handle,
            resolver,
            record,
        }
    }
    /// The handle this wrapper resolves.
    #[inline]
    #[must_use]
    pub const fn handle(&self) -> CarryDepthObservableHandle<H> {
        self.handle
    }
    /// The resolver supplied at construction.
    #[inline]
    #[must_use]
    pub const fn resolver(&self) -> &'r R {
        self.resolver
    }
    /// The cached record, or `None` when the resolver returned `None`.
    #[inline]
    #[must_use]
    pub const fn record(&self) -> Option<&CarryDepthObservableRecord<H>> {
        self.record.as_ref()
    }
}
impl<'r, R: CarryDepthObservableResolver<H>, H: HostTypes> crate::bridge::observable::Observable<H>
    for ResolvedCarryDepthObservable<'r, R, H>
{
    fn value(&self) -> H::Decimal {
        H::EMPTY_DECIMAL
    }
    fn source(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn target(&self) -> &H::HostString {
        H::EMPTY_HOST_STRING
    }
    fn has_unit(&self) -> MeasurementUnit {
        <MeasurementUnit>::default()
    }
}
impl<'r, R: CarryDepthObservableResolver<H>, H: HostTypes> CarryDepthObservable<H>
    for ResolvedCarryDepthObservable<'r, R, H>
{
}