@@ -2301,255 +2301,6 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
23012301 }
23022302}
23032303
2304- /// An iterator over a slice in (non-overlapping) chunks (`N` elements at a
2305- /// time), starting at the beginning of the slice.
2306- ///
2307- /// When the slice len is not evenly divided by the chunk size, the last
2308- /// up to `N-1` elements will be omitted but can be retrieved from
2309- /// the [`remainder`] function from the iterator.
2310- ///
2311- /// This struct is created by the [`array_chunks`] method on [slices].
2312- ///
2313- /// # Example
2314- ///
2315- /// ```
2316- /// #![feature(array_chunks)]
2317- ///
2318- /// let slice = ['l', 'o', 'r', 'e', 'm'];
2319- /// let mut iter = slice.array_chunks::<2>();
2320- /// assert_eq!(iter.next(), Some(&['l', 'o']));
2321- /// assert_eq!(iter.next(), Some(&['r', 'e']));
2322- /// assert_eq!(iter.next(), None);
2323- /// ```
2324- ///
2325- /// [`array_chunks`]: slice::array_chunks
2326- /// [`remainder`]: ArrayChunks::remainder
2327- /// [slices]: slice
2328- #[ derive( Debug ) ]
2329- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2330- #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2331- pub struct ArrayChunks < ' a , T : ' a , const N : usize > {
2332- iter : Iter < ' a , [ T ; N ] > ,
2333- rem : & ' a [ T ] ,
2334- }
2335-
2336- impl < ' a , T , const N : usize > ArrayChunks < ' a , T , N > {
2337- #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
2338- #[ inline]
2339- pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
2340- let ( array_slice, rem) = slice. as_chunks ( ) ;
2341- Self { iter : array_slice. iter ( ) , rem }
2342- }
2343-
2344- /// Returns the remainder of the original slice that is not going to be
2345- /// returned by the iterator. The returned slice has at most `N-1`
2346- /// elements.
2347- #[ must_use]
2348- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2349- pub fn remainder ( & self ) -> & ' a [ T ] {
2350- self . rem
2351- }
2352- }
2353-
2354- // FIXME(#26925) Remove in favor of `#[derive(Clone)]`
2355- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2356- impl < T , const N : usize > Clone for ArrayChunks < ' _ , T , N > {
2357- fn clone ( & self ) -> Self {
2358- ArrayChunks { iter : self . iter . clone ( ) , rem : self . rem }
2359- }
2360- }
2361-
2362- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2363- impl < ' a , T , const N : usize > Iterator for ArrayChunks < ' a , T , N > {
2364- type Item = & ' a [ T ; N ] ;
2365-
2366- #[ inline]
2367- fn next ( & mut self ) -> Option < & ' a [ T ; N ] > {
2368- self . iter . next ( )
2369- }
2370-
2371- #[ inline]
2372- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2373- self . iter . size_hint ( )
2374- }
2375-
2376- #[ inline]
2377- fn count ( self ) -> usize {
2378- self . iter . count ( )
2379- }
2380-
2381- #[ inline]
2382- fn nth ( & mut self , n : usize ) -> Option < Self :: Item > {
2383- self . iter . nth ( n)
2384- }
2385-
2386- #[ inline]
2387- fn last ( self ) -> Option < Self :: Item > {
2388- self . iter . last ( )
2389- }
2390-
2391- unsafe fn __iterator_get_unchecked ( & mut self , i : usize ) -> & ' a [ T ; N ] {
2392- // SAFETY: The safety guarantees of `__iterator_get_unchecked` are
2393- // transferred to the caller.
2394- unsafe { self . iter . __iterator_get_unchecked ( i) }
2395- }
2396- }
2397-
2398- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2399- impl < ' a , T , const N : usize > DoubleEndedIterator for ArrayChunks < ' a , T , N > {
2400- #[ inline]
2401- fn next_back ( & mut self ) -> Option < & ' a [ T ; N ] > {
2402- self . iter . next_back ( )
2403- }
2404-
2405- #[ inline]
2406- fn nth_back ( & mut self , n : usize ) -> Option < Self :: Item > {
2407- self . iter . nth_back ( n)
2408- }
2409- }
2410-
2411- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2412- impl < T , const N : usize > ExactSizeIterator for ArrayChunks < ' _ , T , N > {
2413- fn is_empty ( & self ) -> bool {
2414- self . iter . is_empty ( )
2415- }
2416- }
2417-
2418- #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
2419- unsafe impl < T , const N : usize > TrustedLen for ArrayChunks < ' _ , T , N > { }
2420-
2421- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2422- impl < T , const N : usize > FusedIterator for ArrayChunks < ' _ , T , N > { }
2423-
2424- #[ doc( hidden) ]
2425- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2426- unsafe impl < ' a , T , const N : usize > TrustedRandomAccess for ArrayChunks < ' a , T , N > { }
2427-
2428- #[ doc( hidden) ]
2429- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2430- unsafe impl < ' a , T , const N : usize > TrustedRandomAccessNoCoerce for ArrayChunks < ' a , T , N > {
2431- const MAY_HAVE_SIDE_EFFECT : bool = false ;
2432- }
2433-
2434- /// An iterator over a slice in (non-overlapping) mutable chunks (`N` elements
2435- /// at a time), starting at the beginning of the slice.
2436- ///
2437- /// When the slice len is not evenly divided by the chunk size, the last
2438- /// up to `N-1` elements will be omitted but can be retrieved from
2439- /// the [`into_remainder`] function from the iterator.
2440- ///
2441- /// This struct is created by the [`array_chunks_mut`] method on [slices].
2442- ///
2443- /// # Example
2444- ///
2445- /// ```
2446- /// #![feature(array_chunks)]
2447- ///
2448- /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2449- /// let iter = slice.array_chunks_mut::<2>();
2450- /// ```
2451- ///
2452- /// [`array_chunks_mut`]: slice::array_chunks_mut
2453- /// [`into_remainder`]: ../../std/slice/struct.ArrayChunksMut.html#method.into_remainder
2454- /// [slices]: slice
2455- #[ derive( Debug ) ]
2456- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2457- #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2458- pub struct ArrayChunksMut < ' a , T : ' a , const N : usize > {
2459- iter : IterMut < ' a , [ T ; N ] > ,
2460- rem : & ' a mut [ T ] ,
2461- }
2462-
2463- impl < ' a , T , const N : usize > ArrayChunksMut < ' a , T , N > {
2464- #[ rustc_const_unstable( feature = "const_slice_make_iter" , issue = "137737" ) ]
2465- #[ inline]
2466- pub ( super ) const fn new ( slice : & ' a mut [ T ] ) -> Self {
2467- let ( array_slice, rem) = slice. as_chunks_mut ( ) ;
2468- Self { iter : array_slice. iter_mut ( ) , rem }
2469- }
2470-
2471- /// Returns the remainder of the original slice that is not going to be
2472- /// returned by the iterator. The returned slice has at most `N-1`
2473- /// elements.
2474- #[ must_use = "`self` will be dropped if the result is not used" ]
2475- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2476- pub fn into_remainder ( self ) -> & ' a mut [ T ] {
2477- self . rem
2478- }
2479- }
2480-
2481- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2482- impl < ' a , T , const N : usize > Iterator for ArrayChunksMut < ' a , T , N > {
2483- type Item = & ' a mut [ T ; N ] ;
2484-
2485- #[ inline]
2486- fn next ( & mut self ) -> Option < & ' a mut [ T ; N ] > {
2487- self . iter . next ( )
2488- }
2489-
2490- #[ inline]
2491- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2492- self . iter . size_hint ( )
2493- }
2494-
2495- #[ inline]
2496- fn count ( self ) -> usize {
2497- self . iter . count ( )
2498- }
2499-
2500- #[ inline]
2501- fn nth ( & mut self , n : usize ) -> Option < Self :: Item > {
2502- self . iter . nth ( n)
2503- }
2504-
2505- #[ inline]
2506- fn last ( self ) -> Option < Self :: Item > {
2507- self . iter . last ( )
2508- }
2509-
2510- unsafe fn __iterator_get_unchecked ( & mut self , i : usize ) -> & ' a mut [ T ; N ] {
2511- // SAFETY: The safety guarantees of `__iterator_get_unchecked` are transferred to
2512- // the caller.
2513- unsafe { self . iter . __iterator_get_unchecked ( i) }
2514- }
2515- }
2516-
2517- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2518- impl < ' a , T , const N : usize > DoubleEndedIterator for ArrayChunksMut < ' a , T , N > {
2519- #[ inline]
2520- fn next_back ( & mut self ) -> Option < & ' a mut [ T ; N ] > {
2521- self . iter . next_back ( )
2522- }
2523-
2524- #[ inline]
2525- fn nth_back ( & mut self , n : usize ) -> Option < Self :: Item > {
2526- self . iter . nth_back ( n)
2527- }
2528- }
2529-
2530- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2531- impl < T , const N : usize > ExactSizeIterator for ArrayChunksMut < ' _ , T , N > {
2532- fn is_empty ( & self ) -> bool {
2533- self . iter . is_empty ( )
2534- }
2535- }
2536-
2537- #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
2538- unsafe impl < T , const N : usize > TrustedLen for ArrayChunksMut < ' _ , T , N > { }
2539-
2540- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2541- impl < T , const N : usize > FusedIterator for ArrayChunksMut < ' _ , T , N > { }
2542-
2543- #[ doc( hidden) ]
2544- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2545- unsafe impl < ' a , T , const N : usize > TrustedRandomAccess for ArrayChunksMut < ' a , T , N > { }
2546-
2547- #[ doc( hidden) ]
2548- #[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2549- unsafe impl < ' a , T , const N : usize > TrustedRandomAccessNoCoerce for ArrayChunksMut < ' a , T , N > {
2550- const MAY_HAVE_SIDE_EFFECT : bool = false ;
2551- }
2552-
25532304/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a
25542305/// time), starting at the end of the slice.
25552306///
0 commit comments