diff options
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r-- | crates/test_utils/src/minicore.rs | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 769028580..ce6ad8541 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -15,13 +15,14 @@ | |||
15 | //! range: | 15 | //! range: |
16 | //! deref: sized | 16 | //! deref: sized |
17 | //! deref_mut: deref | 17 | //! deref_mut: deref |
18 | //! index: sized | ||
18 | //! fn: | 19 | //! fn: |
19 | //! pin: | 20 | //! pin: |
20 | //! future: pin | 21 | //! future: pin |
21 | //! option: | 22 | //! option: |
22 | //! result: | 23 | //! result: |
23 | //! iterator: option | 24 | //! iterator: option |
24 | //! iterators: iterator | 25 | //! iterators: iterator, fn |
25 | //! default: sized | 26 | //! default: sized |
26 | //! clone: sized | 27 | //! clone: sized |
27 | //! copy: clone | 28 | //! copy: clone |
@@ -167,6 +168,48 @@ pub mod ops { | |||
167 | }; | 168 | }; |
168 | // endregion:deref | 169 | // endregion:deref |
169 | 170 | ||
171 | // region:index | ||
172 | mod index { | ||
173 | #[lang = "index"] | ||
174 | pub trait Index<Idx: ?Sized> { | ||
175 | type Output: ?Sized; | ||
176 | fn index(&self, index: Idx) -> &Self::Output; | ||
177 | } | ||
178 | #[lang = "index_mut"] | ||
179 | pub trait IndexMut<Idx: ?Sized>: Index<Idx> { | ||
180 | fn index_mut(&mut self, index: Idx) -> &mut Self::Output; | ||
181 | } | ||
182 | |||
183 | // region:slice | ||
184 | impl<T, I> Index<I> for [T] | ||
185 | where | ||
186 | I: SliceIndex<[T]>, | ||
187 | { | ||
188 | type Output = I::Output; | ||
189 | fn index(&self, index: I) -> &I::Output { | ||
190 | loop {} | ||
191 | } | ||
192 | } | ||
193 | impl<T, I> IndexMut<I> for [T] | ||
194 | where | ||
195 | I: SliceIndex<[T]>, | ||
196 | { | ||
197 | fn index_mut(&mut self, index: I) -> &mut I::Output { | ||
198 | loop {} | ||
199 | } | ||
200 | } | ||
201 | |||
202 | pub unsafe trait SliceIndex<T: ?Sized> { | ||
203 | type Output: ?Sized; | ||
204 | } | ||
205 | unsafe impl<T> SliceIndex<[T]> for usize { | ||
206 | type Output = T; | ||
207 | } | ||
208 | // endregion:slice | ||
209 | } | ||
210 | pub use self::index::{Index, IndexMut}; | ||
211 | // endregion:index | ||
212 | |||
170 | // region:range | 213 | // region:range |
171 | mod range { | 214 | mod range { |
172 | #[lang = "RangeFull"] | 215 | #[lang = "RangeFull"] |
@@ -347,7 +390,6 @@ pub mod iter { | |||
347 | iter: I, | 390 | iter: I, |
348 | n: usize, | 391 | n: usize, |
349 | } | 392 | } |
350 | |||
351 | impl<I> Iterator for Take<I> | 393 | impl<I> Iterator for Take<I> |
352 | where | 394 | where |
353 | I: Iterator, | 395 | I: Iterator, |
@@ -358,6 +400,22 @@ pub mod iter { | |||
358 | loop {} | 400 | loop {} |
359 | } | 401 | } |
360 | } | 402 | } |
403 | |||
404 | pub struct FilterMap<I, F> { | ||
405 | iter: I, | ||
406 | f: F, | ||
407 | } | ||
408 | impl<B, I: Iterator, F> Iterator for FilterMap<I, F> | ||
409 | where | ||
410 | F: FnMut(I::Item) -> Option<B>, | ||
411 | { | ||
412 | type Item = B; | ||
413 | |||
414 | #[inline] | ||
415 | fn next(&mut self) -> Option<B> { | ||
416 | loop {} | ||
417 | } | ||
418 | } | ||
361 | } | 419 | } |
362 | pub use self::adapters::Take; | 420 | pub use self::adapters::Take; |
363 | 421 | ||
@@ -405,6 +463,13 @@ pub mod iter { | |||
405 | fn take(self, n: usize) -> crate::iter::Take<Self> { | 463 | fn take(self, n: usize) -> crate::iter::Take<Self> { |
406 | loop {} | 464 | loop {} |
407 | } | 465 | } |
466 | fn filter_map<B, F>(self, f: F) -> crate::iter::FilterMap<Self, F> | ||
467 | where | ||
468 | Self: Sized, | ||
469 | F: FnMut(Self::Item) -> Option<B>, | ||
470 | { | ||
471 | loop {} | ||
472 | } | ||
408 | // endregion:iterators | 473 | // endregion:iterators |
409 | } | 474 | } |
410 | impl<I: Iterator + ?Sized> Iterator for &mut I { | 475 | impl<I: Iterator + ?Sized> Iterator for &mut I { |