@@ -28,8 +28,8 @@ macro_rules! bitnz {
2828
2929/// Constant-time analogue of `bool` providing a "best effort" optimization barrier.
3030///
31- /// Attempts to hint to the compiler and its codegen backends that optimizations should not be
32- /// applied which depend on a value .
31+ /// This type attempts to hint to the compiler and its codegen backends that optimizations should
32+ /// not be applied which depend on specific values of this type .
3333///
3434/// This is used as a "belt-and-suspenders" defense in addition to mechanisms like
3535/// constant-time predication intrinsics provided by the [`cmov`] crate, and is never expected to be
@@ -96,21 +96,21 @@ impl Choice {
9696
9797 // i64
9898
99- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
99+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
100100 #[ inline]
101101 pub const fn from_i64_eq ( x : i64 , y : i64 ) -> Self {
102102 Self :: from_u64_nz ( x as u64 ^ y as u64 ) . not ( )
103103 }
104104
105105 // u8
106106
107- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
107+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
108108 #[ inline]
109109 pub const fn from_u8_eq ( x : u8 , y : u8 ) -> Self {
110110 Self :: from_u8_nz ( x ^ y) . not ( )
111111 }
112112
113- /// Returns the truthy value if `x <= y` and the falsy value otherwise.
113+ /// Returns [`Choice::TRUE`] if `x <= y` and [`Choice::FALSE`] otherwise.
114114 #[ inline]
115115 pub const fn from_u8_le ( x : u8 , y : u8 ) -> Self {
116116 Self :: from_u8_lsb ( bitle ! ( x, y, u8 :: BITS ) )
@@ -122,27 +122,27 @@ impl Choice {
122122 Self ( value & 0x1 )
123123 }
124124
125- /// Returns the truthy value if `x < y`, and the falsy value otherwise.
125+ /// Returns [`Choice::TRUE`] if `x < y`, and [`Choice::FALSE`] otherwise.
126126 #[ inline]
127127 pub const fn from_u8_lt ( x : u8 , y : u8 ) -> Self {
128128 Self :: from_u8_lsb ( bitlt ! ( x, y, u8 :: BITS ) )
129129 }
130130
131- /// Returns the truthy value if `value != 0`, and the falsy value otherwise.
131+ /// Returns [`Choice::TRUE`] if `value != 0`, and [`Choice::FALSE`] otherwise.
132132 #[ inline]
133133 pub const fn from_u8_nz ( value : u8 ) -> Self {
134134 Self :: from_u8_lsb ( bitnz ! ( value, u8 :: BITS ) )
135135 }
136136
137137 // u16
138138
139- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
139+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
140140 #[ inline]
141141 pub const fn from_u16_eq ( x : u16 , y : u16 ) -> Self {
142142 Self :: from_u16_nz ( x ^ y) . not ( )
143143 }
144144
145- /// Returns the truthy value if `x <= y` and the falsy value otherwise.
145+ /// Returns [`Choice::TRUE`] if `x <= y` and [`Choice::FALSE`] otherwise.
146146 #[ inline]
147147 pub const fn from_u16_le ( x : u16 , y : u16 ) -> Self {
148148 Self :: from_u16_lsb ( bitle ! ( x, y, u16 :: BITS ) )
@@ -154,27 +154,27 @@ impl Choice {
154154 Self ( ( value & 0x1 ) as u8 )
155155 }
156156
157- /// Returns the truthy value if `x < y`, and the falsy value otherwise.
157+ /// Returns [`Choice::TRUE`] if `x < y`, and [`Choice::FALSE`] otherwise.
158158 #[ inline]
159159 pub const fn from_u16_lt ( x : u16 , y : u16 ) -> Self {
160160 Self :: from_u16_lsb ( bitlt ! ( x, y, u16 :: BITS ) )
161161 }
162162
163- /// Returns the truthy value if `value != 0`, and the falsy value otherwise.
163+ /// Returns [`Choice::TRUE`] if `value != 0`, and [`Choice::FALSE`] otherwise.
164164 #[ inline]
165165 pub const fn from_u16_nz ( value : u16 ) -> Self {
166166 Self :: from_u16_lsb ( bitnz ! ( value, u16 :: BITS ) )
167167 }
168168
169169 // u32
170170
171- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
171+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
172172 #[ inline]
173173 pub const fn from_u32_eq ( x : u32 , y : u32 ) -> Self {
174174 Self :: from_u32_nz ( x ^ y) . not ( )
175175 }
176176
177- /// Returns the truthy value if `x <= y` and the falsy value otherwise.
177+ /// Returns [`Choice::TRUE`] if `x <= y` and [`Choice::FALSE`] otherwise.
178178 #[ inline]
179179 pub const fn from_u32_le ( x : u32 , y : u32 ) -> Self {
180180 Self :: from_u32_lsb ( bitle ! ( x, y, u32 :: BITS ) )
@@ -186,27 +186,27 @@ impl Choice {
186186 Self ( ( value & 0x1 ) as u8 )
187187 }
188188
189- /// Returns the truthy value if `x < y`, and the falsy value otherwise.
189+ /// Returns [`Choice::TRUE`] if `x < y`, and [`Choice::FALSE`] otherwise.
190190 #[ inline]
191191 pub const fn from_u32_lt ( x : u32 , y : u32 ) -> Self {
192192 Self :: from_u32_lsb ( bitlt ! ( x, y, u32 :: BITS ) )
193193 }
194194
195- /// Returns the truthy value if `value != 0`, and the falsy value otherwise.
195+ /// Returns [`Choice::TRUE`] if `value != 0`, and [`Choice::FALSE`] otherwise.
196196 #[ inline]
197197 pub const fn from_u32_nz ( value : u32 ) -> Self {
198198 Self :: from_u32_lsb ( bitnz ! ( value, u32 :: BITS ) )
199199 }
200200
201201 // u64
202202
203- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
203+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
204204 #[ inline]
205205 pub const fn from_u64_eq ( x : u64 , y : u64 ) -> Self {
206206 Self :: from_u64_nz ( x ^ y) . not ( )
207207 }
208208
209- /// Returns the truthy value if `x <= y` and the falsy value otherwise.
209+ /// Returns [`Choice::TRUE`] if `x <= y` and [`Choice::FALSE`] otherwise.
210210 #[ inline]
211211 pub const fn from_u64_le ( x : u64 , y : u64 ) -> Self {
212212 Self :: from_u64_lsb ( bitle ! ( x, y, u64 :: BITS ) )
@@ -218,27 +218,27 @@ impl Choice {
218218 Self ( ( value & 0x1 ) as u8 )
219219 }
220220
221- /// Returns the truthy value if `x < y`, and the falsy value otherwise.
221+ /// Returns [`Choice::TRUE`] if `x < y`, and [`Choice::FALSE`] otherwise.
222222 #[ inline]
223223 pub const fn from_u64_lt ( x : u64 , y : u64 ) -> Self {
224224 Self :: from_u64_lsb ( bitlt ! ( x, y, u64 :: BITS ) )
225225 }
226226
227- /// Returns the truthy value if `value != 0`, and the falsy value otherwise.
227+ /// Returns [`Choice::TRUE`] if `value != 0`, and [`Choice::FALSE`] otherwise.
228228 #[ inline]
229229 pub const fn from_u64_nz ( value : u64 ) -> Self {
230230 Self :: from_u64_lsb ( bitnz ! ( value, u64 :: BITS ) )
231231 }
232232
233233 // u128
234234
235- /// Returns the truthy value if `x == y`, and the falsy value otherwise.
235+ /// Returns [`Choice::TRUE`] if `x == y`, and [`Choice::FALSE`] otherwise.
236236 #[ inline]
237237 pub const fn from_u128_eq ( x : u128 , y : u128 ) -> Self {
238238 Self :: from_u128_nz ( x ^ y) . not ( )
239239 }
240240
241- /// Returns the truthy value if `x <= y` and the falsy value otherwise.
241+ /// Returns [`Choice::TRUE`] if `x <= y` and [`Choice::FALSE`] otherwise.
242242 #[ inline]
243243 pub const fn from_u128_le ( x : u128 , y : u128 ) -> Self {
244244 Self :: from_u128_lsb ( bitle ! ( x, y, u128 :: BITS ) )
@@ -250,13 +250,13 @@ impl Choice {
250250 Self ( ( value & 1 ) as u8 )
251251 }
252252
253- /// Returns the truthy value if `x < y`, and the falsy value otherwise.
253+ /// Returns [`Choice::TRUE`] if `x < y`, and [`Choice::FALSE`] otherwise.
254254 #[ inline]
255255 pub const fn from_u128_lt ( x : u128 , y : u128 ) -> Self {
256256 Self :: from_u128_lsb ( bitlt ! ( x, y, u128 :: BITS ) )
257257 }
258258
259- /// Returns the truthy value if `value != 0`, and the falsy value otherwise.
259+ /// Returns [`Choice::TRUE`] if `value != 0`, and [`Choice::FALSE`] otherwise.
260260 #[ inline]
261261 pub const fn from_u128_nz ( value : u128 ) -> Self {
262262 Self :: from_u128_lsb ( bitnz ! ( value, u128 :: BITS ) )
@@ -266,7 +266,7 @@ impl Choice {
266266 // `const fn` predication methods
267267 //
268268
269- /// `const fn` helper: return `b` if `self` is truthy , otherwise return `a`.
269+ /// `const fn` helper: return `b` if `self` is [`Choice::TRUE`] , otherwise return `a`.
270270 ///
271271 /// Only use this instead of the [`CtSelect`] trait in the event you're in a `const fn` context
272272 /// and can't use the trait. The former will provide better constant-time assurances.
@@ -275,7 +275,7 @@ impl Choice {
275275 self . select_u64 ( a as u64 , b as u64 ) as i64
276276 }
277277
278- /// `const fn` helper: return `b` if `self` is truthy , otherwise return `a`.
278+ /// `const fn` helper: return `b` if `self` is [`Choice::TRUE`] , otherwise return `a`.
279279 ///
280280 /// Only use this instead of the [`CtSelect`] trait in the event you're in a `const fn` context
281281 /// and can't use the trait. The former will provide better constant-time assurances.
@@ -284,7 +284,7 @@ impl Choice {
284284 a ^ ( self . to_u32_mask ( ) & ( a ^ b) )
285285 }
286286
287- /// `const fn` helper: return `b` if `self` is truthy , otherwise return `a`.
287+ /// `const fn` helper: return `b` if `self` is [`Choice::TRUE`] , otherwise return `a`.
288288 ///
289289 /// Only use this instead of the [`CtSelect`] trait in the event you're in a `const fn` context
290290 /// and can't use the trait. The former will provide better constant-time assurances.
@@ -293,7 +293,7 @@ impl Choice {
293293 a ^ ( self . to_u64_mask ( ) & ( a ^ b) )
294294 }
295295
296- /// `const fn` helper: return `b` if `self` is truthy , otherwise return `a`.
296+ /// `const fn` helper: return `b` if `self` is [`Choice::TRUE`] , otherwise return `a`.
297297 ///
298298 /// Only use this instead of the [`CtSelect`] trait in the event you're in a `const fn` context
299299 /// and can't use the trait. The former will provide better constant-time assurances.
0 commit comments