当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust zip用法及代码示例


本文简要介绍rust语言中 Function core::iter::zip 的用法。

用法

pub fn zip<A, B>(a: A, b: B) -> Zip<A::IntoIter, B::IntoIter> where    A: IntoIterator,    B: IntoIterator,

将参数转换为迭代器并压缩它们。

有关更多信息,请参阅 Iterator::zip 的文档。

例子

#![feature(iter_zip)]
use std::iter::zip;

let xs = [1, 2, 3];
let ys = [4, 5, 6];
for (x, y) in zip(&xs, &ys) {
    println!("x:{}, y:{}", x, y);
}

// 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);
}

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 Function core::iter::zip。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。