Rollup merge of #118586 - gurry:118571-improve-slice-doc-example, r=thomcc

Improve example in `slice::windows()` doc

Fixes #118571

Now using a window of 3 instead 2 because it removes any confusion about exactly how consecutive windows overlap
This commit is contained in:
Takayuki Maeda 2023-12-04 21:19:45 +09:00 committed by GitHub
commit f1397e6ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1045,11 +1045,11 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// let slice = ['r', 'u', 's', 't'];
/// let mut iter = slice.windows(2);
/// assert_eq!(iter.next().unwrap(), &['r', 'u']);
/// assert_eq!(iter.next().unwrap(), &['u', 's']);
/// assert_eq!(iter.next().unwrap(), &['s', 't']);
/// let slice = ['l', 'o', 'r', 'e', 'm'];
/// let mut iter = slice.windows(3);
/// assert_eq!(iter.next().unwrap(), &['l', 'o', 'r']);
/// assert_eq!(iter.next().unwrap(), &['o', 'r', 'e']);
/// assert_eq!(iter.next().unwrap(), &['r', 'e', 'm']);
/// assert!(iter.next().is_none());
/// ```
///