1use crate::{
2 BumpString, BumpVec, FixedBumpVec, MutBumpString, MutBumpVec, MutBumpVecRev,
3 traits::{BumpAllocatorTyped, MutBumpAllocatorTyped},
4};
5
6macro_rules! impl_slice_eq {
7 ([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?) => {
8 impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
9 where
10 T: PartialEq<U>,
11 $($ty: $bound)?
12 {
13 #[inline]
14 fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
15 #[inline]
16 fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
17 }
18 }
19}
20
21impl_slice_eq! { [] FixedBumpVec<'_, T>, FixedBumpVec<'_, U> }
22impl_slice_eq! { [] FixedBumpVec<'_, T>, [U] }
23impl_slice_eq! { [] FixedBumpVec<'_, T>, &[U] }
24impl_slice_eq! { [] FixedBumpVec<'_, T>, &mut [U] }
25impl_slice_eq! { [] [T], FixedBumpVec<'_, U> }
26impl_slice_eq! { [] &[T], FixedBumpVec<'_, U> }
27impl_slice_eq! { [] &mut [T], FixedBumpVec<'_, U> }
28impl_slice_eq! { [const N: usize] FixedBumpVec<'_, T>, [U; N] }
29impl_slice_eq! { [const N: usize] FixedBumpVec<'_, T>, &[U; N] }
30impl_slice_eq! { [const N: usize] FixedBumpVec<'_, T>, &mut [U; N] }
31
32impl_slice_eq! { [A1: BumpAllocatorTyped, A2: BumpAllocatorTyped] BumpVec<T, A1>, BumpVec<U, A2> }
33impl_slice_eq! { [A: BumpAllocatorTyped] BumpVec<T, A>, [U] }
34impl_slice_eq! { [A: BumpAllocatorTyped] BumpVec<T, A>, &[U] }
35impl_slice_eq! { [A: BumpAllocatorTyped] BumpVec<T, A>, &mut [U] }
36impl_slice_eq! { [A: BumpAllocatorTyped] [T], BumpVec<U, A> }
37impl_slice_eq! { [A: BumpAllocatorTyped] &[T], BumpVec<U, A> }
38impl_slice_eq! { [A: BumpAllocatorTyped] &mut [T], BumpVec<U, A> }
39impl_slice_eq! { [A: BumpAllocatorTyped, const N: usize] BumpVec<T, A>, [U; N] }
40impl_slice_eq! { [A: BumpAllocatorTyped, const N: usize] BumpVec<T, A>, &[U; N] }
41impl_slice_eq! { [A: BumpAllocatorTyped, const N: usize] BumpVec<T, A>, &mut [U; N] }
42
43impl_slice_eq! { [A1: MutBumpAllocatorTyped, A2: MutBumpAllocatorTyped] MutBumpVec<T, A1>, MutBumpVec<U, A2> }
44impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVec<T, A>, [U] }
45impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVec<T, A>, &[U] }
46impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVec<T, A>, &mut [U] }
47impl_slice_eq! { [A: MutBumpAllocatorTyped] [T], MutBumpVec<U, A> }
48impl_slice_eq! { [A: MutBumpAllocatorTyped] &[T], MutBumpVec<U, A> }
49impl_slice_eq! { [A: MutBumpAllocatorTyped] &mut [T], MutBumpVec<U, A> }
50impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVec<T, A>, [U; N] }
51impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVec<T, A>, &[U; N] }
52impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVec<T, A>, &mut [U; N] }
53
54impl_slice_eq! { [A1: MutBumpAllocatorTyped, A2: MutBumpAllocatorTyped] MutBumpVecRev<T, A1>, MutBumpVecRev<U, A2> }
55impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVecRev<T, A>, [U] }
56impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVecRev<T, A>, &[U] }
57impl_slice_eq! { [A: MutBumpAllocatorTyped] MutBumpVecRev<T, A>, &mut [U] }
58impl_slice_eq! { [A: MutBumpAllocatorTyped] [T], MutBumpVecRev<U, A> }
59impl_slice_eq! { [A: MutBumpAllocatorTyped] &[T], MutBumpVecRev<U, A> }
60impl_slice_eq! { [A: MutBumpAllocatorTyped] &mut [T], MutBumpVecRev<U, A> }
61impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVecRev<T, A>, [U; N] }
62impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVecRev<T, A>, &[U; N] }
63impl_slice_eq! { [A: MutBumpAllocatorTyped, const N: usize] MutBumpVecRev<T, A>, &mut [U; N] }
64
65macro_rules! impl_str_eq {
66 ([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?) => {
67 impl<$($vars)*> PartialEq<$rhs> for $lhs
68 where
69 $($ty: $bound)?
70 {
71 #[inline]
72 fn eq(&self, other: &$rhs) -> bool { &self[..] == &other[..] }
73 #[inline]
74 fn ne(&self, other: &$rhs) -> bool { &self[..] != &other[..] }
75 }
76 }
77}
78
79impl_str_eq! { [A1: BumpAllocatorTyped, A2: BumpAllocatorTyped] BumpString<A1>, BumpString<A2> }
80impl_str_eq! { [A: BumpAllocatorTyped] BumpString<A>, str }
81impl_str_eq! { [A: BumpAllocatorTyped] BumpString<A>, &str }
82impl_str_eq! { [A: BumpAllocatorTyped] BumpString<A>, &mut str }
83impl_str_eq! { [A: BumpAllocatorTyped] str, BumpString<A> }
84impl_str_eq! { [A: BumpAllocatorTyped] &str, BumpString<A> }
85impl_str_eq! { [A: BumpAllocatorTyped] &mut str, BumpString<A> }
86
87impl_str_eq! { [A1, A2] MutBumpString<A1>, MutBumpString<A2> }
88impl_str_eq! { [A] MutBumpString<A>, str }
89impl_str_eq! { [A] MutBumpString<A>, &str }
90impl_str_eq! { [A] MutBumpString<A>, &mut str }
91impl_str_eq! { [A] str, MutBumpString<A> }
92impl_str_eq! { [A] &str, MutBumpString<A> }
93impl_str_eq! { [A] &mut str, MutBumpString<A> }
94
95#[cfg(feature = "alloc")]
96mod alloc_impl {
97 use super::*;
98
99 use alloc_crate::{borrow::Cow, string::String};
100
101 impl_str_eq! { [A: BumpAllocatorTyped] BumpString<A>, String }
102 impl_str_eq! { [A: BumpAllocatorTyped] String, BumpString<A> }
103 impl_str_eq! { [A: BumpAllocatorTyped] BumpString<A>, Cow<'_, str> }
104 impl_str_eq! { [A: BumpAllocatorTyped] Cow<'_, str>, BumpString<A> }
105
106 impl_str_eq! { [A] MutBumpString<A>, String }
107 impl_str_eq! { [A] String, MutBumpString<A> }
108 impl_str_eq! { [A] MutBumpString<A>, Cow<'_, str> }
109 impl_str_eq! { [A] Cow<'_, str>, MutBumpString<A> }
110}