Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 41 additions & 45 deletions src/comparisons.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,55 @@
use crate::SmallVec;

impl<T, U, const N: usize, const M: usize> PartialEq<SmallVec<U, M>> for SmallVec<T, N>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &SmallVec<U, M>) -> bool {
self.as_slice().eq(other.as_slice())
use {
crate::SmallVec,
alloc::{
borrow::Cow,
collections::VecDeque,
vec::Vec
}
}
impl<T, const N: usize> Eq for SmallVec<T, N> where T: Eq {}
};

impl<T, U, const N: usize, const M: usize> PartialEq<[U; M]> for SmallVec<T, N>
where T: PartialEq<U>
{
#[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<T, U, $($vars)*> PartialEq<$rhs> for $lhs
where
T: PartialEq<U>,
$($ty: $bound)?
{
#[inline]
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
}
};
}

impl<T, U, const N: usize, const M: usize> PartialEq<&[U; M]> for SmallVec<T, N>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &&[U; M]) -> bool {
self[..] == other[..]
}
}

impl<T, U, const N: usize> PartialEq<[U]> for SmallVec<T, N>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &[U]) -> bool {
self[..] == other[..]
}
}
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, [U; N] }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, &[U; N] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, [U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, &[U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, &mut [U] }
__impl_slice_eq1! { [const N: usize] [T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] &[T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] &mut [T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] Vec<T>, SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, Vec<U> }
__impl_slice_eq1! { [const N: usize] Cow<'_, [T]>, SmallVec<U, N> where T: Clone }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, Cow<'_, [U]> where U: Clone }

impl<T, U, const N: usize> PartialEq<&[U]> for SmallVec<T, N>
impl<T, U, const N: usize> PartialEq<SmallVec<U, N>> for VecDeque<T>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &&[U]) -> bool {
self[..] == other[..]
fn eq(&self, other: &SmallVec<U, N>) -> 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<T, U, const N: usize> PartialEq<&mut [U]> for SmallVec<T, N>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &&mut [U]) -> bool {
self[..] == other[..]
}
}
impl<T, const N: usize> Eq for SmallVec<T, N> where T: Eq {}

impl<T, const N: usize> PartialOrd for SmallVec<T, N>
where T: PartialOrd
Expand Down