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 cca032e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
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::{Choice, index_mutually_exclusive_logical_results};
///
/// let r = [0xA, 0xB, 0xC];
///
/// let a = index_mutually_exclusive_logical_results(&r, [Choice::from(0), Choice::from(0)]);
/// assert_eq!(*a, 0xA);
/// let b = index_mutually_exclusive_logical_results(&r, [Choice::from(1), Choice::from(0)]);
/// assert_eq!(*b, 0xB);
/// let c = index_mutually_exclusive_logical_results(&r, [Choice::from(0), Choice::from(1)]);
/// 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 cca032e

Please sign in to comment.