Doc example improvements for slice::windows
.
* Modify existing example to not rely on printing to see results * Add an example demonstrating when slice is shorter than `size`
This commit is contained in:
parent
e7c822cee2
commit
c77f8ce7c3
1 changed files with 14 additions and 7 deletions
|
@ -544,14 +544,21 @@ impl<T> [T] {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Print the adjacent pairs of a slice (i.e. `[1,2]`, `[2,3]`,
|
/// ```
|
||||||
/// `[3,4]`):
|
/// 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']);
|
||||||
|
/// assert!(iter.next().is_none());
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// If the slice is shorter than `size`:
|
||||||
/// let v = &[1, 2, 3, 4];
|
///
|
||||||
/// for win in v.windows(2) {
|
/// ```
|
||||||
/// println!("{:?}", win);
|
/// let slice = ['f', 'o', 'o'];
|
||||||
/// }
|
/// let mut iter = slice.windows(4);
|
||||||
|
/// assert!(iter.next().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue