From 534c6baf8b7a5c74bbd6356f85182530bbb4a125 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 9fc143b..21b4159 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,6 +286,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. ///