pub trait ContentEq {
// Required method
fn content_eq(&self, other: &Self) -> bool;
// Provided method
fn content_ne(&self, other: &Self) -> bool { ... }
}Expand description
This trait works similarly to PartialEq but it gives the liberty of checking the equality of the content loosely.
This would mean the implementor can skip some parts of the content while doing equality checks. As an example, In AST types we ignore fields such as crate::Span.
One should always prefer using the PartialEq over this since implementations of this trait inherently are slower or in the best-case scenario as fast as the PartialEq comparison.
Required Methods§
Sourcefn content_eq(&self, other: &Self) -> bool
fn content_eq(&self, other: &Self) -> bool
This method tests for contents of self and other to be equal.
Provided Methods§
Sourcefn content_ne(&self, other: &Self) -> bool
fn content_ne(&self, other: &Self) -> bool
This method tests for contents of self and other not to be equal.
The default implementation is almost always
sufficient, and should not be overridden without very good reason.
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.
Implementations on Foreign Types§
Source§impl ContentEq for &str
impl ContentEq for &str
fn content_eq(&self, other: &&str) -> bool
fn content_ne(&self, other: &&str) -> bool
Source§impl ContentEq for bool
impl ContentEq for bool
fn content_eq(&self, other: &bool) -> bool
fn content_ne(&self, other: &bool) -> bool
Source§impl ContentEq for char
impl ContentEq for char
fn content_eq(&self, other: &char) -> bool
fn content_ne(&self, other: &char) -> bool
Source§impl ContentEq for f64
Compare f64 as bits instead of using ==.
impl ContentEq for f64
Compare f64 as bits instead of using ==.
Result is the same as partial_eq (==), with the following exceptions:
+0and-0are notcontent_eq(they arepartial_eq).f64::NANandf64::NANarecontent_eq(they are notpartial_eq).
§NaN
Comparison of NaN is complicated. From Rust’s docs for f64:
Note that IEEE 754 doesn’t define just a single NaN value; a plethora of bit patterns are considered to be NaN.
https://doc.rust-lang.org/std/primitive.f64.html#associatedconstant.NAN
If either value is NaN, f64::content_eq only returns true if both are the same NaN,
with the same bit pattern. This means, for example:
f64::NAN.content_eq(f64::NAN) == true
f64::NAN.content_eq(-f64::NAN) == false
f64::NAN.content_eq(--f64::NAN) == trueAny other NaNs which are created through an arithmetic operation, rather than explicitly
with f64::NAN, are not guaranteed to equal f64::NAN.
// This results in `false` on at least some flavors of `x84_64`,
// but that's not specified - could also result in `true`!
(-1f64).sqrt().content_eq(f64::NAN) == falsefn content_eq(&self, other: &Self) -> bool
Source§impl ContentEq for i8
impl ContentEq for i8
fn content_eq(&self, other: &i8) -> bool
fn content_ne(&self, other: &i8) -> bool
Source§impl ContentEq for i16
impl ContentEq for i16
fn content_eq(&self, other: &i16) -> bool
fn content_ne(&self, other: &i16) -> bool
Source§impl ContentEq for i32
impl ContentEq for i32
fn content_eq(&self, other: &i32) -> bool
fn content_ne(&self, other: &i32) -> bool
Source§impl ContentEq for i64
impl ContentEq for i64
fn content_eq(&self, other: &i64) -> bool
fn content_ne(&self, other: &i64) -> bool
Source§impl ContentEq for i128
impl ContentEq for i128
fn content_eq(&self, other: &i128) -> bool
fn content_ne(&self, other: &i128) -> bool
Source§impl ContentEq for isize
impl ContentEq for isize
fn content_eq(&self, other: &isize) -> bool
fn content_ne(&self, other: &isize) -> bool
Source§impl ContentEq for u8
impl ContentEq for u8
fn content_eq(&self, other: &u8) -> bool
fn content_ne(&self, other: &u8) -> bool
Source§impl ContentEq for u16
impl ContentEq for u16
fn content_eq(&self, other: &u16) -> bool
fn content_ne(&self, other: &u16) -> bool
Source§impl ContentEq for u32
impl ContentEq for u32
fn content_eq(&self, other: &u32) -> bool
fn content_ne(&self, other: &u32) -> bool
Source§impl ContentEq for u64
impl ContentEq for u64
fn content_eq(&self, other: &u64) -> bool
fn content_ne(&self, other: &u64) -> bool
Source§impl ContentEq for u128
impl ContentEq for u128
fn content_eq(&self, other: &u128) -> bool
fn content_ne(&self, other: &u128) -> bool
Source§impl ContentEq for ()
impl ContentEq for ()
fn content_eq(&self, _other: &()) -> bool
fn content_ne(&self, _other: &()) -> bool
Source§impl ContentEq for usize
impl ContentEq for usize
fn content_eq(&self, other: &usize) -> bool
fn content_ne(&self, other: &usize) -> bool
Source§impl<T: ContentEq> ContentEq for Option<T>
Blanket implementation for Option types
impl<T: ContentEq> ContentEq for Option<T>
Blanket implementation for Option types
fn content_eq(&self, other: &Self) -> bool
Source§impl<T: ContentEq> ContentEq for Box<'_, T>
Blanket implementation for oxc_allocator::Box types
impl<T: ContentEq> ContentEq for Box<'_, T>
Blanket implementation for oxc_allocator::Box types
fn content_eq(&self, other: &Self) -> bool
Source§impl<T: ContentEq> ContentEq for Vec<'_, T>
Blanket implementation for oxc_allocator::Vec types
impl<T: ContentEq> ContentEq for Vec<'_, T>
Blanket implementation for oxc_allocator::Vec types
§Warning
This implementation is slow compared to PartialEq for native types which are Copy (e.g. u32).
Prefer comparing the 2 vectors using == if they contain such native types (e.g. Vec<u32>).
https://godbolt.org/z/54on5sMWc