Skip to content

Commit

Permalink
expose index_mutually_exclusive_logical_results()
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jul 1, 2022
1 parent 99b2b29 commit 14d884c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl From<u8> for Choice {
}
}

/// An `Eq`-like trait that produces a `Choice` instead of a `bool`.
/// An [`Eq`]-like trait that produces a `Choice` instead of a `bool`.
///
/// # Example
///
Expand Down Expand Up @@ -822,7 +822,20 @@ pub trait ConstantTimePartialOrd {
///
/// This method requires a whole set of logical checks to be performed before evaluating their
/// result, and uses a lookup table to avoid branching in a `match` expression.
fn index_mutually_exclusive_logical_results<T, const N: usize>(
///
///```
/// use subtle_ng::index_mutually_exclusive_logical_results;
///
/// let r = [0xA, 0xB, 0xC];
///
/// let a = index_mutually_exclusive_logical_results(&r, [0.into(), 0.into()]);
/// assert_eq!(*a, 0xA);
/// let b = index_mutually_exclusive_logical_results(&r, [1.into(), 0.into()]);
/// assert_eq!(*b, 0xB);
/// let c = index_mutually_exclusive_logical_results(&r, [0.into(), 1.into()]);
/// assert_eq!(*c, 0xC);
///```
pub fn index_mutually_exclusive_logical_results<T, const N: usize>(
results: &[T],
logicals: [Choice; N],
) -> &T {
Expand Down

0 comments on commit 14d884c

Please sign in to comment.