Rollup merge of #91711 - andrewbanchich:improve-zip-example, r=Mark-Simulacrum

Improve `std::iter::zip` example

`println!` isn't great for doc comments / tests.
This commit is contained in:
Matthias Krüger 2021-12-11 16:02:48 +01:00 committed by GitHub
commit 94ac197585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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>