Skip to content

Commit

Permalink
Add a marker trait for equality testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jul 5, 2024
1 parent 369e746 commit 71f1aef
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ pub trait ConstantTimeEq {
}
}

/// A marker trait indicating that `Eq` equality testing uses `ConstantTimeEq` under the hood.
///
/// Even though `Eq`-based equality testing returns a `bool`, it's a common design pattern
/// to have some types implement this using `ConstantTimeEq`, and then coerce the resulting
/// `Choice` into a `bool`.
///
/// This marker trait should be used if and only if you do this, in order to signal this
/// functionality to implementers.
pub trait EqIsConstantTimeEq {}

impl<T: ConstantTimeEq> ConstantTimeEq for [T] {
/// Check whether two slices of `ConstantTimeEq` types are equal.
///
Expand Down

0 comments on commit 71f1aef

Please sign in to comment.