2022-12-13 20:00:24 -06:00
|
|
|
use std::collections::hash_set::Iter;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
|
|
fn iter_to_vec<'b, X>(i: Iter<'b, X>) -> Vec<X> {
|
|
|
|
let i = i.map(|x| x.clone());
|
|
|
|
i.collect() //~ ERROR E0277
|
|
|
|
}
|
|
|
|
|
2022-12-06 11:34:24 -06:00
|
|
|
fn main() {
|
|
|
|
let scores = vec![(0, 0)]
|
|
|
|
.iter()
|
|
|
|
.map(|(a, b)| {
|
|
|
|
a + b;
|
|
|
|
});
|
|
|
|
println!("{}", scores.sum::<i32>()); //~ ERROR E0277
|
|
|
|
println!(
|
|
|
|
"{}",
|
2022-12-11 16:49:50 -06:00
|
|
|
vec![0, 1]
|
2022-12-06 11:34:24 -06:00
|
|
|
.iter()
|
2022-12-06 12:32:49 -06:00
|
|
|
.map(|x| x * 2)
|
|
|
|
.map(|x| x as f64)
|
|
|
|
.map(|x| x as i64)
|
|
|
|
.filter(|x| *x > 0)
|
|
|
|
.map(|x| { x + 1 })
|
2022-12-06 11:34:24 -06:00
|
|
|
.map(|x| { x; })
|
2022-12-11 16:49:50 -06:00
|
|
|
.sum::<i32>(), //~ ERROR E0277
|
2022-12-06 11:34:24 -06:00
|
|
|
);
|
2022-12-07 16:16:37 -06:00
|
|
|
println!(
|
|
|
|
"{}",
|
2022-12-11 16:49:50 -06:00
|
|
|
vec![0, 1]
|
2022-12-07 16:16:37 -06:00
|
|
|
.iter()
|
|
|
|
.map(|x| x * 2)
|
|
|
|
.map(|x| x as f64)
|
|
|
|
.filter(|x| *x > 0.0)
|
|
|
|
.map(|x| { x + 1.0 })
|
2022-12-11 16:49:50 -06:00
|
|
|
.sum::<i32>(), //~ ERROR E0277
|
2022-12-07 16:16:37 -06:00
|
|
|
);
|
2022-12-06 11:34:24 -06:00
|
|
|
println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); //~ ERROR E0277
|
|
|
|
println!("{}", vec![(), ()].iter().sum::<i32>()); //~ ERROR E0277
|
2022-12-07 13:11:06 -06:00
|
|
|
let a = vec![0];
|
|
|
|
let b = a.into_iter();
|
|
|
|
let c = b.map(|x| x + 1);
|
|
|
|
let d = c.filter(|x| *x > 10 );
|
|
|
|
let e = d.map(|x| {
|
|
|
|
x + 1;
|
|
|
|
});
|
|
|
|
let f = e.filter(|_| false);
|
|
|
|
let g: Vec<i32> = f.collect(); //~ ERROR E0277
|
2022-12-13 20:00:24 -06:00
|
|
|
|
|
|
|
let mut s = HashSet::new();
|
|
|
|
s.insert(1u8);
|
|
|
|
println!("{:?}", iter_to_vec(s.iter()));
|
2022-12-06 11:34:24 -06:00
|
|
|
}
|