Skip to content

Commit 98993af

Browse files
committed
add examples to chunks remainder methods. Also fixed some links to rchunk remainder methods.
1 parent 911cbf8 commit 98993af

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

library/core/src/slice/iter.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,20 @@ impl<'a, T> ChunksExact<'a, T> {
18341834
/// Returns the remainder of the original slice that is not going to be
18351835
/// returned by the iterator. The returned slice has at most `chunk_size-1`
18361836
/// elements.
1837+
///
1838+
/// # Example
1839+
///
1840+
/// ```
1841+
/// let slice = ['l', 'o', 'r', 'e', 'm'];
1842+
/// let mut iter = slice.chunks_exact(2);
1843+
/// assert_eq!(iter.remainder(), &['m'][..]);
1844+
/// assert_eq!(iter.next(), Some(&['l', 'o'][..]));
1845+
/// assert_eq!(iter.remainder(), &['m'][..]);
1846+
/// assert_eq!(iter.next(), Some(&['r', 'e'][..]));
1847+
/// assert_eq!(iter.remainder(), &['m'][..]);
1848+
/// assert_eq!(iter.next(), None);
1849+
/// assert_eq!(iter.remainder(), &['m'][..]);
1850+
/// ```
18371851
#[must_use]
18381852
#[stable(feature = "chunks_exact", since = "1.31.0")]
18391853
pub fn remainder(&self) -> &'a [T] {
@@ -2869,7 +2883,7 @@ unsafe impl<T> Sync for RChunksMut<'_, T> where T: Sync {}
28692883
/// ```
28702884
///
28712885
/// [`rchunks_exact`]: slice::rchunks_exact
2872-
/// [`remainder`]: ChunksExact::remainder
2886+
/// [`remainder`]: RChunksExact::remainder
28732887
/// [slices]: slice
28742888
#[derive(Debug)]
28752889
#[stable(feature = "rchunks", since = "1.31.0")]
@@ -2892,6 +2906,20 @@ impl<'a, T> RChunksExact<'a, T> {
28922906
/// Returns the remainder of the original slice that is not going to be
28932907
/// returned by the iterator. The returned slice has at most `chunk_size-1`
28942908
/// elements.
2909+
///
2910+
/// # Example
2911+
///
2912+
/// ```
2913+
/// let slice = ['l', 'o', 'r', 'e', 'm'];
2914+
/// let mut iter = slice.rchunks_exact(2);
2915+
/// assert_eq!(iter.remainder(), &['l'][..]);
2916+
/// assert_eq!(iter.next(), Some(&['e', 'm'][..]));
2917+
/// assert_eq!(iter.remainder(), &['l'][..]);
2918+
/// assert_eq!(iter.next(), Some(&['o', 'r'][..]));
2919+
/// assert_eq!(iter.remainder(), &['l'][..]);
2920+
/// assert_eq!(iter.next(), None);
2921+
/// assert_eq!(iter.remainder(), &['l'][..]);
2922+
/// ```
28952923
#[must_use]
28962924
#[stable(feature = "rchunks", since = "1.31.0")]
28972925
pub fn remainder(&self) -> &'a [T] {
@@ -3031,7 +3059,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
30313059
/// ```
30323060
///
30333061
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
3034-
/// [`into_remainder`]: ChunksExactMut::into_remainder
3062+
/// [`into_remainder`]: RChunksExactMut::into_remainder
30353063
/// [slices]: slice
30363064
#[derive(Debug)]
30373065
#[stable(feature = "rchunks", since = "1.31.0")]

0 commit comments

Comments
 (0)