diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-07-24 15:18:48 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-24 15:18:48 +0530 |
| commit | 89b9ddd0ddab2af0f6923244047c7c9fa216a048 (patch) | |
| tree | eb9e89d9e8341c1d3f874cfa6d220cca9b2a2221 | |
| parent | f7df83d115b543b0f417eb7b07b4b416990e44a8 (diff) | |
| parent | c77f8ce7c3284441a00faed6782d08eb5a78296c (diff) | |
| download | rust-89b9ddd0ddab2af0f6923244047c7c9fa216a048.tar.gz rust-89b9ddd0ddab2af0f6923244047c7c9fa216a048.zip | |
Rollup merge of #34988 - frewsxcv:vec-windows, r=GuillaumeGomez
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`
| -rw-r--r-- | src/libcollections/slice.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 2c54dc13c8d..1f8eea56fc6 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -544,14 +544,21 @@ impl<T> [T] { /// /// # 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 - /// let v = &[1, 2, 3, 4]; - /// for win in v.windows(2) { - /// println!("{:?}", win); - /// } + /// If the slice is shorter than `size`: + /// + /// ``` + /// let slice = ['f', 'o', 'o']; + /// let mut iter = slice.windows(4); + /// assert!(iter.next().is_none()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] |
