pub trait ContentEq {
#[must_use]
fn content_eq(&self, other: &Self) -> bool;
#[inline]
#[must_use]
fn content_ne(&self, other: &Self) -> bool {
!self.content_eq(other)
}
}
impl ContentEq for () {
#[inline]
fn content_eq(&self, _other: &()) -> bool {
true
}
#[inline]
fn content_ne(&self, _other: &()) -> bool {
false
}
}
impl ContentEq for f64 {
#[inline]
fn content_eq(&self, other: &Self) -> bool {
self.to_bits() == other.to_bits()
}
}
impl<T: ContentEq> ContentEq for Option<T> {
#[inline]
fn content_eq(&self, other: &Self) -> bool {
#[expect(clippy::match_same_arms)]
match (self, other) {
(Some(lhs), Some(rhs)) => lhs.content_eq(rhs),
(Some(_), None) => false,
(None, Some(_)) => false,
(None, None) => true,
}
}
}
impl<T: ContentEq> ContentEq for oxc_allocator::Box<'_, T> {
#[inline]
fn content_eq(&self, other: &Self) -> bool {
self.as_ref().content_eq(other.as_ref())
}
}
impl<T: ContentEq> ContentEq for oxc_allocator::Vec<'_, T> {
#[inline]
fn content_eq(&self, other: &Self) -> bool {
if self.len() == other.len() {
!self.iter().zip(other).any(|(lhs, rhs)| lhs.content_ne(rhs))
} else {
false
}
}
}
mod content_eq_auto_impls {
use super::ContentEq;
macro_rules! content_eq_impl {
($($t:ty)*) => ($(
impl ContentEq for $t {
#[inline]
fn content_eq(&self, other: &$t) -> bool { (*self) == (*other) }
#[inline]
fn content_ne(&self, other: &$t) -> bool { (*self) != (*other) }
}
)*)
}
content_eq_impl! {
char &str
bool isize usize
u8 u16 u32 u64 u128
i8 i16 i32 i64 i128
}
}