partial_eq.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: Apache-2.0 OR MIT
  2. use crate::alloc::Allocator;
  3. #[cfg(not(no_global_oom_handling))]
  4. use crate::borrow::Cow;
  5. use super::Vec;
  6. macro_rules! __impl_slice_eq1 {
  7. ([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
  8. #[$stability]
  9. impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
  10. where
  11. T: PartialEq<U>,
  12. $($ty: $bound)?
  13. {
  14. #[inline]
  15. fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
  16. #[inline]
  17. fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
  18. }
  19. }
  20. }
  21. __impl_slice_eq1! { [A1: Allocator, A2: Allocator] Vec<T, A1>, Vec<U, A2>, #[stable(feature = "rust1", since = "1.0.0")] }
  22. __impl_slice_eq1! { [A: Allocator] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] }
  23. __impl_slice_eq1! { [A: Allocator] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] }
  24. __impl_slice_eq1! { [A: Allocator] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
  25. __impl_slice_eq1! { [A: Allocator] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
  26. __impl_slice_eq1! { [A: Allocator] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
  27. __impl_slice_eq1! { [A: Allocator] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
  28. #[cfg(not(no_global_oom_handling))]
  29. __impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
  30. #[cfg(not(no_global_oom_handling))]
  31. __impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
  32. #[cfg(not(no_global_oom_handling))]
  33. __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
  34. __impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] }
  35. __impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] }
  36. // NOTE: some less important impls are omitted to reduce code bloat
  37. // FIXME(Centril): Reconsider this?
  38. //__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], }
  39. //__impl_slice_eq1! { [const N: usize] [A; N], Vec<B>, }
  40. //__impl_slice_eq1! { [const N: usize] &[A; N], Vec<B>, }
  41. //__impl_slice_eq1! { [const N: usize] &mut [A; N], Vec<B>, }
  42. //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], }
  43. //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
  44. //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }