如题所示,代码如下:
fn main(){
let mut v = vec![9,5,2,7];
let mut k:Vec<_>= v.iter_mut().map(|x|*x+1).collect();
k.push(13);
let m:Vec<_> =v.into_iter().chain(k).collect();
println!(" 合并或关联两个 {:?}",m);
let n:Vec<_> = m.iter().take(3).collect();
println!(" 取前n个 {:?}",n);
let n:Vec<_> = m.iter().skip(3).collect();
println!(" 跳过前n个 {:?}",n);
for (i,e) in n.iter().enumerate(){
println!(" enumerate {}-{}",i,e);
}
let v = vec![1,2,3,4];
let n = vec!["one","two","three","four"];
let z1:Vec<_> = n.iter().zip(v.iter()).collect();
println!("{:?}",z1);
let v = vec![9,5,2,7];
let t = v.iter().any(|x| x%2==0);
println!(" 有偶数吗?{}",t);
let t = v.iter().all(|x|x>&5);
println!(" 全部都大于5吗?{}",t);
}
/*输出效果
合并或关联两个 [9, 5, 2, 7, 10, 6, 3, 8, 13]
取前n个 [9, 5, 2]
跳过前n个 [7, 10, 6, 3, 8, 13]
enumerate 0-7
enumerate 1-10
enumerate 2-6
enumerate 3-3
enumerate 4-8
enumerate 5-13
[("one", 1), ("two", 2), ("three", 3), ("four", 4)]
有偶数吗?true
全部都大于5吗?false
*/