Move the PartialEq
and Eq
impls for arrays to a separate file
This commit is contained in:
parent
aa65b08b1d
commit
d05eafae2f
111
library/core/src/array/equality.rs
Normal file
111
library/core/src/array/equality.rs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
|
||||||
|
where
|
||||||
|
A: PartialEq<B>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &[B; N]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &[B; N]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<[B]> for [A; N]
|
||||||
|
where
|
||||||
|
A: PartialEq<B>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &[B]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &[B]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<[A; N]> for [B]
|
||||||
|
where
|
||||||
|
B: PartialEq<A>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<&[B]> for [A; N]
|
||||||
|
where
|
||||||
|
A: PartialEq<B>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &&[B]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &&[B]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<[A; N]> for &[B]
|
||||||
|
where
|
||||||
|
B: PartialEq<A>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]
|
||||||
|
where
|
||||||
|
A: PartialEq<B>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &&mut [B]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &&mut [B]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<A, B, const N: usize> PartialEq<[A; N]> for &mut [B]
|
||||||
|
where
|
||||||
|
B: PartialEq<A>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] == other[..]
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ne(&self, other: &[A; N]) -> bool {
|
||||||
|
self[..] != other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: some less important impls are omitted to reduce code bloat
|
||||||
|
// __impl_slice_eq2! { [A; $N], &'b [B; $N] }
|
||||||
|
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T: Eq, const N: usize> Eq for [T; N] {}
|
@ -14,6 +14,7 @@
|
|||||||
use crate::ops::{Index, IndexMut};
|
use crate::ops::{Index, IndexMut};
|
||||||
use crate::slice::{Iter, IterMut};
|
use crate::slice::{Iter, IterMut};
|
||||||
|
|
||||||
|
mod equality;
|
||||||
mod iter;
|
mod iter;
|
||||||
|
|
||||||
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
||||||
@ -230,118 +231,6 @@ fn index_mut(&mut self, index: I) -> &mut Self::Output {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
|
|
||||||
where
|
|
||||||
A: PartialEq<B>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &[B; N]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &[B; N]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<[B]> for [A; N]
|
|
||||||
where
|
|
||||||
A: PartialEq<B>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &[B]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &[B]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<[A; N]> for [B]
|
|
||||||
where
|
|
||||||
B: PartialEq<A>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<&[B]> for [A; N]
|
|
||||||
where
|
|
||||||
A: PartialEq<B>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &&[B]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &&[B]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<[A; N]> for &[B]
|
|
||||||
where
|
|
||||||
B: PartialEq<A>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]
|
|
||||||
where
|
|
||||||
A: PartialEq<B>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &&mut [B]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &&mut [B]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<A, B, const N: usize> PartialEq<[A; N]> for &mut [B]
|
|
||||||
where
|
|
||||||
B: PartialEq<A>,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] == other[..]
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
|
||||||
self[..] != other[..]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: some less important impls are omitted to reduce code bloat
|
|
||||||
// __impl_slice_eq2! { [A; $N], &'b [B; $N] }
|
|
||||||
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl<T: Eq, const N: usize> Eq for [T; N] {}
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
|
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
Reference in New Issue
Block a user