diff --git a/src/comparisons.rs b/src/comparisons.rs index 62b6815..3fb7e6a 100644 --- a/src/comparisons.rs +++ b/src/comparisons.rs @@ -1,59 +1,55 @@ -use crate::SmallVec; - -impl PartialEq> for SmallVec -where T: PartialEq -{ - #[inline] - fn eq(&self, other: &SmallVec) -> bool { - self.as_slice().eq(other.as_slice()) +use { + crate::SmallVec, + alloc::{ + borrow::Cow, + collections::VecDeque, + vec::Vec } -} -impl Eq for SmallVec where T: Eq {} +}; -impl PartialEq<[U; M]> for SmallVec -where T: PartialEq -{ - #[inline] - fn eq(&self, other: &[U; M]) -> bool { - self[..] == other[..] - } +macro_rules! __impl_slice_eq1 { + ([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?) => { + impl PartialEq<$rhs> for $lhs + where + T: PartialEq, + $($ty: $bound)? + { + #[inline] + fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] } + } + }; } -impl PartialEq<&[U; M]> for SmallVec -where T: PartialEq -{ - #[inline] - fn eq(&self, other: &&[U; M]) -> bool { - self[..] == other[..] - } -} - -impl PartialEq<[U]> for SmallVec -where T: PartialEq -{ - #[inline] - fn eq(&self, other: &[U]) -> bool { - self[..] == other[..] - } -} +__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec, SmallVec } +__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec, [U; N] } +__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec, &[U; N] } +__impl_slice_eq1! { [const N: usize] SmallVec, [U] } +__impl_slice_eq1! { [const N: usize] SmallVec, &[U] } +__impl_slice_eq1! { [const N: usize] SmallVec, &mut [U] } +__impl_slice_eq1! { [const N: usize] [T], SmallVec } +__impl_slice_eq1! { [const N: usize] &[T], SmallVec } +__impl_slice_eq1! { [const N: usize] &mut [T], SmallVec } +__impl_slice_eq1! { [const N: usize] Vec, SmallVec } +__impl_slice_eq1! { [const N: usize] SmallVec, Vec } +__impl_slice_eq1! { [const N: usize] Cow<'_, [T]>, SmallVec where T: Clone } +__impl_slice_eq1! { [const N: usize] SmallVec, Cow<'_, [U]> where U: Clone } -impl PartialEq<&[U]> for SmallVec +impl PartialEq> for VecDeque where T: PartialEq { #[inline] - fn eq(&self, other: &&[U]) -> bool { - self[..] == other[..] + fn eq(&self, other: &SmallVec) -> bool { + let other = other.as_slice(); + if self.len() != other.len() { + return false; + } + let (sa, sb) = self.as_slices(); + let (oa, ob) = other[..].split_at(sa.len()); + sa == oa && sb == ob } } -impl PartialEq<&mut [U]> for SmallVec -where T: PartialEq -{ - #[inline] - fn eq(&self, other: &&mut [U]) -> bool { - self[..] == other[..] - } -} +impl Eq for SmallVec where T: Eq {} impl PartialOrd for SmallVec where T: PartialOrd