@@ -270,6 +270,13 @@ pub(super) trait SplitIter: DoubleEndedIterator {
270
270
///
271
271
/// This struct is created by the [`split`] method on [slices].
272
272
///
273
+ /// # Example
274
+ ///
275
+ /// ```
276
+ /// let slice = [10, 40, 33, 20];
277
+ /// let mut iter = slice.split(|num| num % 3 == 0);
278
+ /// ```
279
+ ///
273
280
/// [`split`]: ../../std/primitive.slice.html#method.split
274
281
/// [slices]: ../../std/primitive.slice.html
275
282
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -378,6 +385,15 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
378
385
///
379
386
/// This struct is created by the [`split_inclusive`] method on [slices].
380
387
///
388
+ /// # Example
389
+ ///
390
+ /// ```
391
+ /// #![feature(split_inclusive)]
392
+ ///
393
+ /// let slice = [10, 40, 33, 20];
394
+ /// let mut iter = slice.split_inclusive(|num| num % 3 == 0);
395
+ /// ```
396
+ ///
381
397
/// [`split_inclusive`]: ../../std/primitive.slice.html#method.split_inclusive
382
398
/// [slices]: ../../std/primitive.slice.html
383
399
#[ unstable( feature = "split_inclusive" , issue = "72360" ) ]
@@ -476,6 +492,13 @@ impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool
476
492
///
477
493
/// This struct is created by the [`split_mut`] method on [slices].
478
494
///
495
+ /// # Example
496
+ ///
497
+ /// ```
498
+ /// let mut v = [10, 40, 30, 20, 60, 50];
499
+ /// let iter = v.split_mut(|num| *num % 3 == 0);
500
+ /// ```
501
+ ///
479
502
/// [`split_mut`]: ../../std/primitive.slice.html#method.split_mut
480
503
/// [slices]: ../../std/primitive.slice.html
481
504
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -591,6 +614,15 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
591
614
///
592
615
/// This struct is created by the [`split_inclusive_mut`] method on [slices].
593
616
///
617
+ /// # Example
618
+ ///
619
+ /// ```
620
+ /// #![feature(split_inclusive)]
621
+ ///
622
+ /// let mut v = [10, 40, 30, 20, 60, 50];
623
+ /// let iter = v.split_inclusive_mut(|num| *num % 3 == 0);
624
+ /// ```
625
+ ///
594
626
/// [`split_inclusive_mut`]: ../../std/primitive.slice.html#method.split_inclusive_mut
595
627
/// [slices]: ../../std/primitive.slice.html
596
628
#[ unstable( feature = "split_inclusive" , issue = "72360" ) ]
@@ -698,6 +730,13 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
698
730
///
699
731
/// This struct is created by the [`rsplit`] method on [slices].
700
732
///
733
+ /// # Example
734
+ ///
735
+ /// ```
736
+ /// let slice = [11, 22, 33, 0, 44, 55];
737
+ /// let iter = slice.rsplit(|num| *num == 0);
738
+ /// ```
739
+ ///
701
740
/// [`rsplit`]: ../../std/primitive.slice.html#method.rsplit
702
741
/// [slices]: ../../std/primitive.slice.html
703
742
#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
@@ -770,6 +809,13 @@ impl<T, P> FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {}
770
809
///
771
810
/// This struct is created by the [`rsplit_mut`] method on [slices].
772
811
///
812
+ /// # Example
813
+ ///
814
+ /// ```
815
+ /// let mut slice = [11, 22, 33, 0, 44, 55];
816
+ /// let iter = slice.rsplit_mut(|num| *num == 0);
817
+ /// ```
818
+ ///
773
819
/// [`rsplit_mut`]: ../../std/primitive.slice.html#method.rsplit_mut
774
820
/// [slices]: ../../std/primitive.slice.html
775
821
#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
@@ -875,6 +921,13 @@ impl<T, I: SplitIter<Item = T>> Iterator for GenericSplitN<I> {
875
921
///
876
922
/// This struct is created by the [`splitn`] method on [slices].
877
923
///
924
+ /// # Example
925
+ ///
926
+ /// ```
927
+ /// let slice = [10, 40, 30, 20, 60, 50];
928
+ /// let iter = slice.splitn(2, |num| *num % 3 == 0);
929
+ /// ```
930
+ ///
878
931
/// [`splitn`]: ../../std/primitive.slice.html#method.splitn
879
932
/// [slices]: ../../std/primitive.slice.html
880
933
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -901,6 +954,13 @@ where
901
954
///
902
955
/// This struct is created by the [`rsplitn`] method on [slices].
903
956
///
957
+ /// # Example
958
+ ///
959
+ /// ```
960
+ /// let slice = [10, 40, 30, 20, 60, 50];
961
+ /// let iter = slice.rsplitn(2, |num| *num % 3 == 0);
962
+ /// ```
963
+ ///
904
964
/// [`rsplitn`]: ../../std/primitive.slice.html#method.rsplitn
905
965
/// [slices]: ../../std/primitive.slice.html
906
966
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -926,6 +986,13 @@ where
926
986
///
927
987
/// This struct is created by the [`splitn_mut`] method on [slices].
928
988
///
989
+ /// # Example
990
+ ///
991
+ /// ```
992
+ /// let mut slice = [10, 40, 30, 20, 60, 50];
993
+ /// let iter = slice.splitn_mut(2, |num| *num % 3 == 0);
994
+ /// ```
995
+ ///
929
996
/// [`splitn_mut`]: ../../std/primitive.slice.html#method.splitn_mut
930
997
/// [slices]: ../../std/primitive.slice.html
931
998
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -952,6 +1019,13 @@ where
952
1019
///
953
1020
/// This struct is created by the [`rsplitn_mut`] method on [slices].
954
1021
///
1022
+ /// # Example
1023
+ ///
1024
+ /// ```
1025
+ /// let mut slice = [10, 40, 30, 20, 60, 50];
1026
+ /// let iter = slice.rsplitn_mut(2, |num| *num % 3 == 0);
1027
+ /// ```
1028
+ ///
955
1029
/// [`rsplitn_mut`]: ../../std/primitive.slice.html#method.rsplitn_mut
956
1030
/// [slices]: ../../std/primitive.slice.html
957
1031
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -981,6 +1055,13 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
981
1055
///
982
1056
/// This struct is created by the [`windows`] method on [slices].
983
1057
///
1058
+ /// # Example
1059
+ ///
1060
+ /// ```
1061
+ /// let slice = ['r', 'u', 's', 't'];
1062
+ /// let iter = slice.windows(2);
1063
+ /// ```
1064
+ ///
984
1065
/// [`windows`]: ../../std/primitive.slice.html#method.windows
985
1066
/// [slices]: ../../std/primitive.slice.html
986
1067
#[ derive( Debug ) ]
@@ -1113,6 +1194,13 @@ unsafe impl<'a, T> TrustedRandomAccess for Windows<'a, T> {
1113
1194
///
1114
1195
/// This struct is created by the [`chunks`] method on [slices].
1115
1196
///
1197
+ /// # Example
1198
+ ///
1199
+ /// ```
1200
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
1201
+ /// let iter = slice.chunks(2);
1202
+ /// ```
1203
+ ///
1116
1204
/// [`chunks`]: ../../std/primitive.slice.html#method.chunks
1117
1205
/// [slices]: ../../std/primitive.slice.html
1118
1206
#[ derive( Debug ) ]
@@ -1267,6 +1355,13 @@ unsafe impl<'a, T> TrustedRandomAccess for Chunks<'a, T> {
1267
1355
///
1268
1356
/// This struct is created by the [`chunks_mut`] method on [slices].
1269
1357
///
1358
+ /// # Example
1359
+ ///
1360
+ /// ```
1361
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
1362
+ /// let iter = slice.chunks_mut(2);
1363
+ /// ```
1364
+ ///
1270
1365
/// [`chunks_mut`]: ../../std/primitive.slice.html#method.chunks_mut
1271
1366
/// [slices]: ../../std/primitive.slice.html
1272
1367
#[ derive( Debug ) ]
@@ -1419,6 +1514,13 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksMut<'a, T> {
1419
1514
///
1420
1515
/// This struct is created by the [`chunks_exact`] method on [slices].
1421
1516
///
1517
+ /// # Example
1518
+ ///
1519
+ /// ```
1520
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
1521
+ /// let iter = slice.chunks_exact(2);
1522
+ /// ```
1523
+ ///
1422
1524
/// [`chunks_exact`]: ../../std/primitive.slice.html#method.chunks_exact
1423
1525
/// [`remainder`]: ChunksExact::remainder
1424
1526
/// [slices]: ../../std/primitive.slice.html
@@ -1559,6 +1661,13 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExact<'a, T> {
1559
1661
///
1560
1662
/// This struct is created by the [`chunks_exact_mut`] method on [slices].
1561
1663
///
1664
+ /// # Example
1665
+ ///
1666
+ /// ```
1667
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
1668
+ /// let iter = slice.chunks_exact_mut(2);
1669
+ /// ```
1670
+ ///
1562
1671
/// [`chunks_exact_mut`]: ../../std/primitive.slice.html#method.chunks_exact_mut
1563
1672
/// [`into_remainder`]: ChunksExactMut::into_remainder
1564
1673
/// [slices]: ../../std/primitive.slice.html
@@ -1692,6 +1801,15 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {
1692
1801
///
1693
1802
/// This struct is created by the [`array_windows`] method on [slices].
1694
1803
///
1804
+ /// # Example
1805
+ ///
1806
+ /// ```
1807
+ /// #![feature(array_windows)]
1808
+ ///
1809
+ /// let slice = [0, 1, 2, 3];
1810
+ /// let iter = slice.array_windows::<2>();
1811
+ /// ```
1812
+ ///
1695
1813
/// [`array_windows`]: ../../std/primitive.slice.html#method.array_windows
1696
1814
/// [slices]: ../../std/primitive.slice.html
1697
1815
#[ derive( Debug , Clone , Copy ) ]
@@ -1796,6 +1914,15 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
1796
1914
///
1797
1915
/// This struct is created by the [`array_chunks`] method on [slices].
1798
1916
///
1917
+ /// # Example
1918
+ ///
1919
+ /// ```
1920
+ /// #![feature(array_chunks)]
1921
+ ///
1922
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
1923
+ /// let iter = slice.array_chunks::<2>();
1924
+ /// ```
1925
+ ///
1799
1926
/// [`array_chunks`]: ../../std/primitive.slice.html#method.array_chunks
1800
1927
/// [`remainder`]: ArrayChunks::remainder
1801
1928
/// [slices]: ../../std/primitive.slice.html
@@ -1903,6 +2030,15 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunks<'a, T, N>
1903
2030
///
1904
2031
/// This struct is created by the [`array_chunks_mut`] method on [slices].
1905
2032
///
2033
+ /// # Example
2034
+ ///
2035
+ /// ```
2036
+ /// #![feature(array_chunks)]
2037
+ ///
2038
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2039
+ /// let iter = slice.array_chunks_mut::<2>();
2040
+ /// ```
2041
+ ///
1906
2042
/// [`array_chunks_mut`]: ../../std/primitive.slice.html#method.array_chunks_mut
1907
2043
/// [`into_remainder`]: ../../std/slice/struct.ArrayChunksMut.html#method.into_remainder
1908
2044
/// [slices]: ../../std/primitive.slice.html
@@ -2001,6 +2137,13 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunksMut<'a, T,
2001
2137
///
2002
2138
/// This struct is created by the [`rchunks`] method on [slices].
2003
2139
///
2140
+ /// # Example
2141
+ ///
2142
+ /// ```
2143
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
2144
+ /// let iter = slice.rchunks(2);
2145
+ /// ```
2146
+ ///
2004
2147
/// [`rchunks`]: ../../std/primitive.slice.html#method.rchunks
2005
2148
/// [slices]: ../../std/primitive.slice.html
2006
2149
#[ derive( Debug ) ]
@@ -2151,6 +2294,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunks<'a, T> {
2151
2294
///
2152
2295
/// This struct is created by the [`rchunks_mut`] method on [slices].
2153
2296
///
2297
+ /// # Example
2298
+ ///
2299
+ /// ```
2300
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2301
+ /// let iter = slice.rchunks_mut(2);
2302
+ /// ```
2303
+ ///
2154
2304
/// [`rchunks_mut`]: ../../std/primitive.slice.html#method.rchunks_mut
2155
2305
/// [slices]: ../../std/primitive.slice.html
2156
2306
#[ derive( Debug ) ]
@@ -2300,6 +2450,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksMut<'a, T> {
2300
2450
///
2301
2451
/// This struct is created by the [`rchunks_exact`] method on [slices].
2302
2452
///
2453
+ /// # Example
2454
+ ///
2455
+ /// ```
2456
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
2457
+ /// let iter = slice.rchunks_exact(2);
2458
+ /// ```
2459
+ ///
2303
2460
/// [`rchunks_exact`]: ../../std/primitive.slice.html#method.rchunks_exact
2304
2461
/// [`remainder`]: ChunksExact::remainder
2305
2462
/// [slices]: ../../std/primitive.slice.html
@@ -2445,6 +2602,13 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExact<'a, T> {
2445
2602
///
2446
2603
/// This struct is created by the [`rchunks_exact_mut`] method on [slices].
2447
2604
///
2605
+ /// # Example
2606
+ ///
2607
+ /// ```
2608
+ /// let mut slice = ['l', 'o', 'r', 'e', 'm'];
2609
+ /// let iter = slice.rchunks_exact_mut(2);
2610
+ /// ```
2611
+ ///
2448
2612
/// [`rchunks_exact_mut`]: ../../std/primitive.slice.html#method.rchunks_exact_mut
2449
2613
/// [`into_remainder`]: ChunksExactMut::into_remainder
2450
2614
/// [slices]: ../../std/primitive.slice.html
0 commit comments