Skip to content

Commit 534c6ba

Browse files
committed
Add a marker trait for equality testing
1 parent f1f8e53 commit 534c6ba

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
@@ -286,6 +286,16 @@ pub trait ConstantTimeEq {
286286
}
287287
}
288288

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

0 commit comments

Comments
 (0)