Skip to content

Commit 71f1aef

Browse files
committed
Add a marker trait for equality testing
1 parent 369e746 commit 71f1aef

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ pub trait ConstantTimeEq {
285285
}
286286
}
287287

288+
/// A marker trait indicating that `Eq` equality testing uses `ConstantTimeEq` under the hood.
289+
///
290+
/// Even though `Eq`-based equality testing returns a `bool`, it's a common design pattern
291+
/// to have some types implement this using `ConstantTimeEq`, and then coerce the resulting
292+
/// `Choice` into a `bool`.
293+
///
294+
/// This marker trait should be used if and only if you do this, in order to signal this
295+
/// functionality to implementers.
296+
pub trait EqIsConstantTimeEq {}
297+
288298
impl<T: ConstantTimeEq> ConstantTimeEq for [T] {
289299
/// Check whether two slices of `ConstantTimeEq` types are equal.
290300
///

0 commit comments

Comments
 (0)