Improve example in slice::windows() doc

Now using a window of 3 instead 2 because it removes any
confusion about exactly how consecutive windows overlap
This commit is contained in:
Gurinder Singh 2023-12-04 11:17:42 +05:30
parent 85a4bd8f58
commit 423481ba54

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());
/// ```
///