Skip to content

Commit beb17be

Browse files
small refactor + docstring expansion
1 parent 578c8ce commit beb17be

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ use core::option::Option;
115115
pub struct Choice(u8);
116116

117117
impl Choice {
118+
#[inline]
119+
pub(crate) const fn of_bool(of: bool) -> Self {
120+
Self(of as u8)
121+
}
122+
118123
/// Unwrap the `Choice` wrapper to reveal the underlying `u8`.
119124
///
120125
/// # Note
@@ -326,7 +331,7 @@ pub struct IteratedEq {
326331
impl IteratedOperation for IteratedEq {
327332
fn initiate() -> Self {
328333
Self {
329-
still_equal: Choice::from(1),
334+
still_equal: Choice::of_bool(true),
330335
}
331336
}
332337
fn extract_result(self) -> Choice {
@@ -335,7 +340,10 @@ impl IteratedOperation for IteratedEq {
335340
}
336341

337342
impl IteratedEq {
338-
/// Unconditionally AND internal state with the result of an "equals" comparison.
343+
/// Unconditionally AND internal state with the result of a constant-time "equals" comparison.
344+
///
345+
/// [`Self::initiate()`] begins with internal state set to "true", so we can think of this
346+
/// strategy as "assuming equal until proven wrong".
339347
#[inline]
340348
pub fn apply_eq<T: ConstantTimeEq + ?Sized>(&mut self, a: &T, b: &T) {
341349
self.still_equal &= a.ct_eq(b);

0 commit comments

Comments
 (0)