1use crate::{
2 ArrayWindowsBorrowed, ArrayWindowsOwned, Chain, Cycle, FromFn, Interleave, MapBorrowed,
3 MapOwned, Reverse, Slice, SliceBorrowed, SliceOf, SliceOwned, SplitMut, WindowsBorrowed,
4 WindowsOwned, Zip,
5};
6
7macro_rules! impl_eq {
8 ($(
9 $typ:ident [$($lt:lifetime),* $($generics:ident),*]
10 ;)*) => {$(
11 impl<
12 $($lt,)* T, S, O, V $(, $generics)*,
13 > PartialEq<O> for $typ<$($lt,)* S $(, $generics)*>
14 where
15 V: PartialEq<T>,
16 S: SliceOwned<Output = T>,
17 O: Slice<Output = V>,
18 $( $generics: SliceOwned<Output = T>,)*
19 {
20 fn eq(&self, other: &O) -> bool {
21 if self.len() != other.len() {
22 false
23 } else {
24 for i in 0..self.len() {
25 if other
26 .get_with(i, &mut |x| x != &self.get_owned(i).unwrap())
27 .unwrap_or(true)
28 {
29 return false;
30 }
31 }
32
33 true
34 }
35 }
36 }
37 )*};
38}
39
40impl_eq! {
41 Chain[S2];
42 Cycle[];
43 Interleave[S2];
44 Reverse[];
45 SliceOf[];
46 SplitMut['a];
47}
48
49impl<T, S, O, F, U, V> PartialEq<O> for MapOwned<S, F>
50where
51 S: SliceOwned<Output = T>,
52 O: Slice<Output = V>,
53 F: Fn(T) -> U,
54 V: PartialEq<U>,
55{
56 fn eq(&self, other: &O) -> bool {
57 if self.len() != other.len() {
58 false
59 } else {
60 for i in 0..self.len() {
61 if other
62 .get_with(i, &mut |x| x != &self.get_owned(i).unwrap())
63 .unwrap_or(true)
64 {
65 return false;
66 }
67 }
68
69 true
70 }
71 }
72}
73
74impl<T, S, O, F, U, V> PartialEq<O> for MapBorrowed<S, F>
75where
76 S: SliceBorrowed<Output = T>,
77 O: Slice<Output = V>,
78 F: Fn(&T) -> U,
79 V: PartialEq<U>,
80{
81 fn eq(&self, other: &O) -> bool {
82 if self.len() != other.len() {
83 false
84 } else {
85 for i in 0..self.len() {
86 if other
87 .get_with(i, &mut |x| x != &self.get_owned(i).unwrap())
88 .unwrap_or(true)
89 {
90 return false;
91 }
92 }
93
94 true
95 }
96 }
97}
98
99impl<T, O, F, U> PartialEq<O> for FromFn<F>
100where
101 O: Slice<Output = U>,
102 F: Fn(usize) -> Option<T>,
103 U: PartialEq<T>,
104{
105 fn eq(&self, other: &O) -> bool {
106 if self.len() != other.len() {
107 false
108 } else {
109 for i in 0..self.len() {
110 if other
111 .get_with(i, &mut |x| x != &self.get_owned(i).unwrap())
112 .unwrap_or(true)
113 {
114 return false;
115 }
116 }
117
118 true
119 }
120 }
121}
122
123impl<T, O, U, S1, S2> PartialEq<O> for Zip<S1, S2>
124where
125 O: Slice<Output = U>,
126 U: PartialEq<(T, T)>,
127 S1: SliceOwned<Output = T>,
128 S2: SliceOwned<Output = T>,
129{
130 fn eq(&self, other: &O) -> bool {
131 if self.len() != other.len() {
132 false
133 } else {
134 for i in 0..self.len() {
135 if other
136 .get_with(i, &mut |x| x != &self.get_owned(i).unwrap())
137 .unwrap_or(true)
138 {
139 return false;
140 }
141 }
142
143 true
144 }
145 }
146}
147
148impl<'a, T, U, O, S> PartialEq<O> for WindowsOwned<'a, S>
149where
150 O: SliceOwned<Output = U>,
151 SliceOf<&'a S>: PartialEq<U>,
152 S: SliceOwned<Output = T>,
153{
154 fn eq(&self, other: &O) -> bool {
155 if Slice::len(self) != other.len() {
156 false
157 } else {
158 for i in 0..Slice::len(self) {
159 if other
160 .get_with(i, &mut |x| &self.get_owned(i).unwrap() != x)
161 .unwrap_or(true)
162 {
163 return false;
164 }
165 }
166
167 true
168 }
169 }
170}
171
172impl<'a, T, U, O, S> PartialEq<O> for WindowsBorrowed<'a, S>
173where
174 O: SliceBorrowed<Output = U>,
175 SliceOf<&'a S>: PartialEq<U>,
176 S: SliceBorrowed<Output = T>,
177{
178 fn eq(&self, other: &O) -> bool {
179 if Slice::len(self) != other.len() {
180 false
181 } else {
182 for i in 0..Slice::len(self) {
183 if other
184 .get_with(i, &mut |x| &self.get_owned(i).unwrap() != x)
185 .unwrap_or(true)
186 {
187 return false;
188 }
189 }
190
191 true
192 }
193 }
194}
195
196impl<T, U, O, S, const N: usize> PartialEq<O> for ArrayWindowsOwned<S, N>
197where
198 O: SliceOwned<Output = U>,
199 [T; N]: PartialEq<U>,
200 S: SliceOwned<Output = T>,
201{
202 fn eq(&self, other: &O) -> bool {
203 if Slice::len(self) != other.len() {
204 false
205 } else {
206 for i in 0..Slice::len(self) {
207 if other
208 .get_with(i, &mut |x| &self.get_owned(i).unwrap() != x)
209 .unwrap_or(true)
210 {
211 return false;
212 }
213 }
214
215 true
216 }
217 }
218}
219
220impl<'a, T: 'a, U, O, S, const N: usize> PartialEq<O> for ArrayWindowsBorrowed<'a, S, N>
221where
222 O: SliceBorrowed<Output = U>,
223 [&'a T; N]: PartialEq<U>,
224 S: SliceBorrowed<Output = T>,
225{
226 fn eq(&self, other: &O) -> bool {
227 if Slice::len(self) != other.len() {
228 false
229 } else {
230 for i in 0..Slice::len(self) {
231 if other
232 .get_with(i, &mut |x| &self.get_owned(i).unwrap() != x)
233 .unwrap_or(true)
234 {
235 return false;
236 }
237 }
238
239 true
240 }
241 }
242}