pub trait GuaranteesFiniteComplexValues: ValidationPolicyComplex { }Expand description
Marker trait indicating that a validation policy guarantees finite complex values.
This trait serves as a compile-time indicator that a validation policy for
complex numbers ensures all validated values have finite real and imaginary components
(i.e., neither component is NaN or infinity). This guarantee enables the
implementation of Eq and Hash for ComplexValidated types, allowing
them to be used as keys in hash-based collections like HashMap
and HashSet.
§Purpose
Complex numbers can have NaN or infinite components, making equality comparison problematic (NaN != NaN). By guaranteeing finiteness at the policy level, this trait allows:
- Full equality (
Eq) implementation for complex validated types - Consistent hashing (
Hash) for use in hash-based collections - Compile-time verification of these properties
§Design Rationale
This trait works in tandem with GuaranteesFiniteValues for real numbers:
GuaranteesFiniteValues: For real number policiesGuaranteesFiniteComplexValues: For complex number policies
This separation allows different validation strategies for real and complex components while maintaining type safety.
§Currently Implemented By
StrictFinitePolicy<T, P>: Validates both real and imaginary components for finiteness and non-subnormal values.DebugValidationPolicy<StrictFinitePolicy<T, P>>: Applies strict validation only in debug builds.
§Safety and Correctness
This trait should only be implemented by validation policies that genuinely guarantee finite values in both components. Incorrect implementation could lead to hash collisions or violated equality contracts.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.