@@ -319,6 +319,13 @@ pub(super) trait SplitIter: DoubleEndedIterator {
319
319
///
320
320
/// This struct is created by the [`split`] method on [slices].
321
321
///
322
+ /// # Example
323
+ ///
324
+ /// ```
325
+ /// let slice = [10, 40, 33, 20];
326
+ /// let mut iter = slice.split(|num| num % 3 == 0);
327
+ /// ```
328
+ ///
322
329
/// [`split`]: ../../std/primitive.slice.html#method.split
323
330
/// [slices]: ../../std/primitive.slice.html
324
331
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -434,6 +441,15 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
434
441
///
435
442
/// This struct is created by the [`split_inclusive`] method on [slices].
436
443
///
444
+ /// # Example
445
+ ///
446
+ /// ```
447
+ /// #![feature(split_inclusive)]
448
+ ///
449
+ /// let slice = [10, 40, 33, 20];
450
+ /// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
451
+ /// ```
452
+ ///
437
453
/// [`split_inclusive`]: ../../std/primitive.slice.html#method.split_inclusive
438
454
/// [slices]: ../../std/primitive.slice.html
439
455
#[ unstable( feature = "split_inclusive" , issue = "72360" ) ]
@@ -539,6 +555,13 @@ impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool
539
555
///
540
556
/// This struct is created by the [`split_mut`] method on [slices].
541
557
///
558
+ /// # Example
559
+ ///
560
+ /// ```
561
+ /// let mut v = [10, 40, 30, 20, 60, 50];
562
+ /// let iter = v.split_mut(|num| *num % 3 == 0);
563
+ /// ```
564
+ ///
542
565
/// [`split_mut`]: ../../std/primitive.slice.html#method.split_mut
543
566
/// [slices]: ../../std/primitive.slice.html
544
567
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -661,6 +684,15 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
661
684
///
662
685
/// This struct is created by the [`split_inclusive_mut`] method on [slices].
663
686
///
687
+ /// # Example
688
+ ///
689
+ /// ```
690
+ /// #![feature(split_inclusive)]
691
+ ///
692
+ /// let mut v = [10, 40, 30, 20, 60, 50];
693
+ /// let iter = v.split_inclusive_mut(|num| *num % 3 == 0);
694
+ /// ```
695
+ ///
664
696
/// [`split_inclusive_mut`]: ../../std/primitive.slice.html#method.split_inclusive_mut
665
697
/// [slices]: ../../std/primitive.slice.html
666
698
#[ unstable( feature = "split_inclusive" , issue = "72360" ) ]
@@ -775,6 +807,13 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
775
807
///
776
808
/// This struct is created by the [`rsplit`] method on [slices].
777
809
///
810
+ /// # Example
811
+ ///
812
+ /// ```
813
+ /// let slice = [11, 22, 33, 0, 44, 55];
814
+ /// let iter = slice.rsplit(|num| *num == 0);
815
+ /// ```
816
+ ///
778
817
/// [`rsplit`]: ../../std/primitive.slice.html#method.rsplit
779
818
/// [slices]: ../../std/primitive.slice.html
780
819
#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
@@ -854,6 +893,13 @@ impl<T, P> FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {}
854
893
///
855
894
/// This struct is created by the [`rsplit_mut`] method on [slices].
856
895
///
896
+ /// # Example
897
+ ///
898
+ /// ```
899
+ /// let mut slice = [11, 22, 33, 0, 44, 55];
900
+ /// let iter = slice.rsplit_mut(|num| *num == 0);
901
+ /// ```
902
+ ///
857
903
/// [`rsplit_mut`]: ../../std/primitive.slice.html#method.rsplit_mut
858
904
/// [slices]: ../../std/primitive.slice.html
859
905
#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
@@ -966,6 +1012,13 @@ impl<T, I: SplitIter<Item = T>> Iterator for GenericSplitN<I> {
966
1012
///
967
1013
/// This struct is created by the [`splitn`] method on [slices].
968
1014
///
1015
+ /// # Example
1016
+ ///
1017
+ /// ```
1018
+ /// let slice = [10, 40, 30, 20, 60, 50];
1019
+ /// let iter = slice.splitn(2, |num| *num % 3 == 0);
1020
+ /// ```
1021
+ ///
969
1022
/// [`splitn`]: ../../std/primitive.slice.html#method.splitn
970
1023
/// [slices]: ../../std/primitive.slice.html
971
1024
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -999,6 +1052,13 @@ where
999
1052
///
1000
1053
/// This struct is created by the [`rsplitn`] method on [slices].
1001
1054
///
1055
+ /// # Example
1056
+ ///
1057
+ /// ```
1058
+ /// let slice = [10, 40, 30, 20, 60, 50];
1059
+ /// let iter = slice.rsplitn(2, |num| *num % 3 == 0);
1060
+ /// ```
1061
+ ///
1002
1062
/// [`rsplitn`]: ../../std/primitive.slice.html#method.rsplitn
1003
1063
/// [slices]: ../../std/primitive.slice.html
1004
1064
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1031,6 +1091,13 @@ where
1031
1091
///
1032
1092
/// This struct is created by the [`splitn_mut`] method on [slices].
1033
1093
///
1094
+ /// # Example
1095
+ ///
1096
+ /// ```
1097
+ /// let mut slice = [10, 40, 30, 20, 60, 50];
1098
+ /// let iter = slice.splitn_mut(2, |num| *num % 3 == 0);
1099
+ /// ```
1100
+ ///
1034
1101
/// [`splitn_mut`]: ../../std/primitive.slice.html#method.splitn_mut
1035
1102
/// [slices]: ../../std/primitive.slice.html
1036
1103
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1064,6 +1131,13 @@ where
1064
1131
///
1065
1132
/// This struct is created by the [`rsplitn_mut`] method on [slices].
1066
1133
///
1134
+ /// # Example
1135
+ ///
1136
+ /// ```
1137
+ /// let mut slice = [10, 40, 30, 20, 60, 50];
1138
+ /// let iter = slice.rsplitn_mut(2, |num| *num % 3 == 0);
1139
+ /// ```
1140
+ ///
1067
1141
/// [`rsplitn_mut`]: ../../std/primitive.slice.html#method.rsplitn_mut
1068
1142
/// [slices]: ../../std/primitive.slice.html
1069
1143
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1100,6 +1174,13 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
1100
1174
///
1101
1175
/// This struct is created by the [`windows`] method on [slices].
1102
1176
///
1177
+ /// # Example
1178
+ ///
1179
+ /// ```
1180
+ /// let slice = ['r', 'u', 's', 't'];
1181
+ /// let iter = slice.windows(2);
1182
+ /// ```
1183
+ ///
1103
1184
/// [`windows`]: ../../std/primitive.slice.html#method.windows
1104
1185
/// [slices]: ../../std/primitive.slice.html
1105
1186
#[ derive( Debug ) ]
@@ -1239,6 +1320,13 @@ unsafe impl<'a, T> TrustedRandomAccess for Windows<'a, T> {
1239
1320
///
1240
1321
/// This struct is created by the [`chunks`] method on [slices].
1241
1322
///
1323
+ /// # Example
1324
+ ///
1325
+ /// ```
1326
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
1327
+ /// let iter = slice.chunks(2);
1328
+ /// ```
1329
+ ///
1242
1330
/// [`chunks`]: ../../std/primitive.slice.html#method.chunks
1243
1331
/// [slices]: ../../std/primitive.slice.html
1244
1332
#[ derive( Debug ) ]
@@ -1400,6 +1488,13 @@ unsafe impl<'a, T> TrustedRandomAccess for Chunks<'a, T> {
1400
1488
///
1401
1489
/// This struct is created by the [`chunks_mut`] method on [slices].
1402
1490
///
1491
+ /// # Example
1492
+ ///
1493
+ /// ```
1494
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
1495
+ /// let iter = slice.chunks_mut(2);
1496
+ /// ```
1497
+ ///
1403
1498
/// [`chunks_mut`]: ../../std/primitive.slice.html#method.chunks_mut
1404
1499
/// [slices]: ../../std/primitive.slice.html
1405
1500
#[ derive( Debug ) ]
@@ -1559,6 +1654,13 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> {
1559
1654
///
1560
1655
/// This struct is created by the [`chunks_exact`] method on [slices].
1561
1656
///
1657
+ /// # Example
1658
+ ///
1659
+ /// ```
1660
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
1661
+ /// let iter = slice.chunks_exact(2);
1662
+ /// ```
1663
+ ///
1562
1664
/// [`chunks_exact`]: ../../std/primitive.slice.html#method.chunks_exact
1563
1665
/// [`remainder`]: ChunksExact::remainder
1564
1666
/// [slices]: ../../std/primitive.slice.html
@@ -1708,6 +1810,13 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExact<'a, T> {
1708
1810
///
1709
1811
/// This struct is created by the [`chunks_exact_mut`] method on [slices].
1710
1812
///
1813
+ /// # Example
1814
+ ///
1815
+ /// ```
1816
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
1817
+ /// let iter = slice.chunks_exact_mut(2);
1818
+ /// ```
1819
+ ///
1711
1820
/// [`chunks_exact_mut`]: ../../std/primitive.slice.html#method.chunks_exact_mut
1712
1821
/// [`into_remainder`]: ChunksExactMut::into_remainder
1713
1822
/// [slices]: ../../std/primitive.slice.html
@@ -1850,6 +1959,15 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {
1850
1959
///
1851
1960
/// This struct is created by the [`array_windows`] method on [slices].
1852
1961
///
1962
+ /// # Example
1963
+ ///
1964
+ /// ```
1965
+ /// #![feature(array_windows)]
1966
+ ///
1967
+ /// let slice = [0, 1, 2, 3];
1968
+ /// let iter = slice.array_windows::<2>();
1969
+ /// ```
1970
+ ///
1853
1971
/// [`array_windows`]: ../../std/primitive.slice.html#method.array_windows
1854
1972
/// [slices]: ../../std/primitive.slice.html
1855
1973
#[ derive( Debug , Clone , Copy ) ]
@@ -1962,6 +2080,15 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
1962
2080
///
1963
2081
/// This struct is created by the [`array_chunks`] method on [slices].
1964
2082
///
2083
+ /// # Example
2084
+ ///
2085
+ /// ```
2086
+ /// #![feature(array_chunks)]
2087
+ ///
2088
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
2089
+ /// let iter = slice.array_chunks::<2>();
2090
+ /// ```
2091
+ ///
1965
2092
/// [`array_chunks`]: ../../std/primitive.slice.html#method.array_chunks
1966
2093
/// [`remainder`]: ArrayChunks::remainder
1967
2094
/// [slices]: ../../std/primitive.slice.html
@@ -2080,6 +2207,15 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunks<'a, T, N>
2080
2207
///
2081
2208
/// This struct is created by the [`array_chunks_mut`] method on [slices].
2082
2209
///
2210
+ /// # Example
2211
+ ///
2212
+ /// ```
2213
+ /// #![feature(array_chunks)]
2214
+ ///
2215
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2216
+ /// let iter = slice.array_chunks_mut::<2>();
2217
+ /// ```
2218
+ ///
2083
2219
/// [`array_chunks_mut`]: ../../std/primitive.slice.html#method.array_chunks_mut
2084
2220
/// [`into_remainder`]: ../../std/slice/struct.ArrayChunksMut.html#method.into_remainder
2085
2221
/// [slices]: ../../std/primitive.slice.html
@@ -2190,6 +2326,13 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunksMut<'a, T,
2190
2326
///
2191
2327
/// This struct is created by the [`rchunks`] method on [slices].
2192
2328
///
2329
+ /// # Example
2330
+ ///
2331
+ /// ```
2332
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
2333
+ /// let iter = slice.rchunks(2);
2334
+ /// ```
2335
+ ///
2193
2336
/// [`rchunks`]: ../../std/primitive.slice.html#method.rchunks
2194
2337
/// [slices]: ../../std/primitive.slice.html
2195
2338
#[ derive( Debug ) ]
@@ -2347,6 +2490,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunks<'a, T> {
2347
2490
///
2348
2491
/// This struct is created by the [`rchunks_mut`] method on [slices].
2349
2492
///
2493
+ /// # Example
2494
+ ///
2495
+ /// ```
2496
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2497
+ /// let iter = slice.rchunks_mut(2);
2498
+ /// ```
2499
+ ///
2350
2500
/// [`rchunks_mut`]: ../../std/primitive.slice.html#method.rchunks_mut
2351
2501
/// [slices]: ../../std/primitive.slice.html
2352
2502
#[ derive( Debug ) ]
@@ -2504,6 +2654,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksMut<'a, T> {
2504
2654
///
2505
2655
/// This struct is created by the [`rchunks_exact`] method on [slices].
2506
2656
///
2657
+ /// # Example
2658
+ ///
2659
+ /// ```
2660
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
2661
+ /// let iter = slice.rchunks_exact(2);
2662
+ /// ```
2663
+ ///
2507
2664
/// [`rchunks_exact`]: ../../std/primitive.slice.html#method.rchunks_exact
2508
2665
/// [`remainder`]: ChunksExact::remainder
2509
2666
/// [slices]: ../../std/primitive.slice.html
@@ -2657,6 +2814,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExact<'a, T> {
2657
2814
///
2658
2815
/// This struct is created by the [`rchunks_exact_mut`] method on [slices].
2659
2816
///
2817
+ /// # Example
2818
+ ///
2819
+ /// ```
2820
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2821
+ /// let iter = slice.rchunks_exact_mut(2);
2822
+ /// ```
2823
+ ///
2660
2824
/// [`rchunks_exact_mut`]: ../../std/primitive.slice.html#method.rchunks_exact_mut
2661
2825
/// [`into_remainder`]: ChunksExactMut::into_remainder
2662
2826
/// [slices]: ../../std/primitive.slice.html
0 commit comments