Skip to content

Instantly share code, notes, and snippets.

@quux00
Created April 9, 2014 01:52
Show Gist options
  • Select an option

  • Save quux00/10218360 to your computer and use it in GitHub Desktop.

Select an option

Save quux00/10218360 to your computer and use it in GitHub Desktop.
fn main() {
// works
let a = [1, 2, 3, 4, 5];
let b: ~[int] = a.iter().map(|&x| x * 2).collect();
println!("{:?}", b);
// fails
let c = [1, 2, 3, 4, 5];
let d: ~[int] = a.iter().filter(|&x| *x > 2).collect();
println!("{:?}", d);
}
// filter.rs:8:21: 8:59 error: expected std::iter::FromIterator<&int>,
// but found std::iter::FromIterator<int> (expected &-ptr but found int)
// filter.rs:8 let d: ~[int] = a.iter().filter(|&x| *x > 2).collect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment