Skip to content

Commit

Permalink
small refactor + docstring expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jan 1, 2023
1 parent 578c8ce commit beb17be
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ use core::option::Option;
pub struct Choice(u8);

impl Choice {
#[inline]
pub(crate) const fn of_bool(of: bool) -> Self {
Self(of as u8)
}

/// Unwrap the `Choice` wrapper to reveal the underlying `u8`.
///
/// # Note
Expand Down Expand Up @@ -326,7 +331,7 @@ pub struct IteratedEq {
impl IteratedOperation for IteratedEq {
fn initiate() -> Self {
Self {
still_equal: Choice::from(1),
still_equal: Choice::of_bool(true),
}
}
fn extract_result(self) -> Choice {
Expand All @@ -335,7 +340,10 @@ impl IteratedOperation for IteratedEq {
}

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

0 comments on commit beb17be

Please sign in to comment.