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
//! The duration comparison: [`MongoDurationComparison`], the nanosecond integer a duration column
//! holds, and the range the crossing refuses past.
use SignedDuration;
use ;
use crate::;
mongo_comparison_kind!
/// One backend, so one row — and the header is concrete for the coherence reason
/// [`MongoScalarComparison`](super::MongoScalarComparison)'s records.
///
/// `V` is open here and the CROSSING below is not, which is the split
/// [`ToDatabaseComparison`]'s own note describes: a storage form is a declaration rather than a law,
/// so a column that declares its own converter reaches any carrier this backend has, while a column
/// that declares none reaches the one this crate answers with.
/// The crossing with no declared converter, and the ONE storage type it lands on.
///
/// # It names `i64` where every other kind in this family is generic over `V: TryFrom<D>`
///
/// That generic row would be empty here, and it is measured rather than argued: with it in place of
/// this one, `MongoDurationComparison::<i64>::try_from_filter` is `E0599` — *its trait bounds were
/// not satisfied* — because `i64: TryFrom<SignedDuration>` does not hold and no crate but `jiff` may
/// write it. Two types DO satisfy the bound — [`SignedDuration`] reflexively, and
/// [`core::time::Duration`] through jiff's own conversion — and BSON has nothing for either of them
/// to carry as, so neither has a [`MongoCarrier`] row. The generic spelling would compile and be
/// reachable by nothing this backend stores.
///
/// The two spellings also cannot both exist: with the generic one present, a concrete `i64` row is
///
/// ```text
/// error[E0119]: conflicting implementations of trait `TryFromFilter<DurationFilter>`
/// for type `MongoDurationComparison<i64>`
/// = note: upstream crates may add a new impl of trait
/// `std::convert::TryFrom<jiff::SignedDuration>` for type `i64` in future versions
/// ```
///
/// So naming the type is what lets the undeclared crossing reach a CHECKED converter at all.
///
/// # The refusal, and where it is not
///
/// [`DurationFilter::operand_nanos`] is that converter, and its [`DurationOutOfRange`] is this
/// crossing's error rather than a MongoDB-local restatement of it: one refusal has one name, and it
/// is the same one a declared `i64` column gets on Postgres.
///
/// It reads *duration is outside ±`i64` nanoseconds*, which is about 292 years either way — where
/// [`SignedDuration`] reaches about 292 billion. Truncating instead would turn an out-of-range
/// operand into a plausible in-range one and match the wrong documents with nothing to notice; with
/// a SIGNED operand it would also flip the sign, so `292 years + 1ns` becomes a large NEGATIVE
/// count. A MongoDB lowering has no later place to say no either: [`Backend::Error`] for [`Mongo`]
/// is [`Infallible`](core::convert::Infallible), so the crossing is the last position that can
/// refuse.
///
/// ALL EIGHT slots are guarded at BOTH ENDS, `in_` and `not_in` included. One out-of-range element
/// refuses the whole filter rather than being dropped, because a dropped element silently NARROWS
/// `in_` and silently WIDENS `not_in`.
/// The eight operators map one-to-one onto `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`, `$in` and
/// `$nin`, and the walk is the scalar kind's — see it for the two places that mapping is not the
/// identity it looks like, and for why the field path is rendered once.
///
/// # The order `$gt` answers in is the numeric one, and what that rests on is the TYPE
///
/// MongoDB's comparison order puts *Numbers (ints, longs, doubles, decimals)* in ONE bracket, and
/// all numeric types are equivalent within it — so an `Int64` operand is compared by value and the
/// four ordering operators mean what the filter means. The order itself carries no qualification,
/// where the byte kind's does: `BinData` is compared by LENGTH before its bytes, so only a
/// fixed-width column's `$lt` is the bytewise one and a variable-width column's four ordering
/// operators are refused. This kind therefore needs no width and no gate.
///
/// What IS conditional is the bracket itself: MongoDB documents that a comparison operator *only
/// performs comparisons on fields where the BSON type matches the query value's type*, with limited
/// cross-type comparison through type bracketing. So the operand and the stored field have to reach
/// BSON as the same arm — the agreement `carrier`'s module note is about, and the one it had to
/// measure for `u32`, where the serializer widens and [`From`] narrows.
///
/// For `i64` the two routes agree: bson 3.1's `Serializer::serialize_i64` and `impl From<i64> for
/// Bson` are both `Bson::Int64`, with no narrowing arm between them. `carrier`'s row writes that arm
/// directly, so a duration operand and the document field it is compared against are one BSON type.
///
/// Read from MongoDB's documented comparison order rather than measured against a live server, which
/// is the standing the `BinData` rule already has here.