From 71f1aef66f3c7e42f971f24a0b2e27c32f2a7326 Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:15:13 -0500 Subject: [PATCH] Add a marker trait for equality testing --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b6e42c4..2f0b566 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 ConstantTimeEq for [T] { /// Check whether two slices of `ConstantTimeEq` types are equal. ///