pub trait StructuralPartialEq { }
structural_match
#31434)Expand description
Required trait for constants used in pattern matches.
Constants are only allowed as patterns if (a) their type implements
PartialEq
, and (b) interpreting the value of the constant as a pattern
is equivalent to calling PartialEq
. This ensures that constants used as
patterns cannot expose implementation details in an unexpected way or
cause semver hazards.
This trait ensures point (b).
Any type that derives PartialEq
automatically implements this trait.
Implementing this trait (which is unstable) is a way for type authors to explicitly allow
comparing const values of this type; that operation will recursively compare all fields
(including private fields), even if that behavior differs from PartialEq
. This can make it
semver-breaking to add further private fields to a type.