diff options
| author | Andrew Banchich <andrewbanchich@protonmail.ch> | 2021-12-09 10:41:38 -0500 |
|---|---|---|
| committer | Andrew Banchich <andrewbanchich@protonmail.ch> | 2021-12-09 17:29:36 -0500 |
| commit | c78fb62255ea3433baa7612c968065eb4770bcbf (patch) | |
| tree | 54103c78678fefa52dd0d471bc604725ce717550 | |
| parent | 3b263ceb5cb89b6d53b5a03b47ec447c3a7f7765 (diff) | |
| download | rust-c78fb62255ea3433baa7612c968065eb4770bcbf.tar.gz rust-c78fb62255ea3433baa7612c968065eb4770bcbf.zip | |
Improve std::iter::zip example.
Update library/core/src/iter/adapters/zip.rs Co-authored-by: r00ster <r00ster91@protonmail.com> Update library/core/src/iter/adapters/zip.rs Co-authored-by: r00ster <r00ster91@protonmail.com>
| -rw-r--r-- | library/core/src/iter/adapters/zip.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/library/core/src/iter/adapters/zip.rs b/library/core/src/iter/adapters/zip.rs index 4b89bc36326..920fa59c8ad 100644 --- a/library/core/src/iter/adapters/zip.rs +++ b/library/core/src/iter/adapters/zip.rs @@ -45,15 +45,23 @@ impl<A: Iterator, B: Iterator> Zip<A, B> { /// /// let xs = [1, 2, 3]; /// let ys = [4, 5, 6]; -/// for (x, y) in zip(&xs, &ys) { -/// println!("x:{}, y:{}", x, y); -/// } +/// +/// let mut iter = zip(xs, ys); +/// +/// assert_eq!(iter.next().unwrap(), (1, 4)); +/// assert_eq!(iter.next().unwrap(), (2, 5)); +/// assert_eq!(iter.next().unwrap(), (3, 6)); +/// assert!(iter.next().is_none()); /// /// // Nested zips are also possible: /// let zs = [7, 8, 9]; -/// for ((x, y), z) in zip(zip(&xs, &ys), &zs) { -/// println!("x:{}, y:{}, z:{}", x, y, z); -/// } +/// +/// let mut iter = zip(zip(xs, ys), zs); +/// +/// assert_eq!(iter.next().unwrap(), ((1, 4), 7)); +/// assert_eq!(iter.next().unwrap(), ((2, 5), 8)); +/// assert_eq!(iter.next().unwrap(), ((3, 6), 9)); +/// assert!(iter.next().is_none()); /// ``` #[unstable(feature = "iter_zip", issue = "83574")] pub fn zip<A, B>(a: A, b: B) -> Zip<A::IntoIter, B::IntoIter> |
