The problem is in your collect()
call. The iterator is over &uint
, and so collect()
would expect to produce something like ~[&uint]
.
You should change it to use move_iter()
instead of iter()
, or else put in a .map(|&n| n)
.
سؤال
This doesn't seems to work for me (rust-0.10)
let x : ~[uint] = ~[1,2,3];
let sieved: ~[uint] = x.iter().filter(|&n| 3 % n == 0).collect();
...
prob0003.rs:49:77: 49:78 error: mismatched types: expected `<generic integer #5>` but found `&uint` (expected &-ptr but found integral variable)
prob0003.rs:49 let x : ~[uint] = ~[1,2,3]; let sieved: ~[uint] = x.iter().filter(|&n| 3 % n == 0).collect();
المحلول
The problem is in your collect()
call. The iterator is over &uint
, and so collect()
would expect to produce something like ~[&uint]
.
You should change it to use move_iter()
instead of iter()
, or else put in a .map(|&n| n)
.