Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created October 13, 2013 22:23
Show Gist options
  • Select an option

  • Save wilmoore/6968040 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/6968040 to your computer and use it in GitHub Desktop.
I've spent way too much time on this already...
less-than-100.rs:1:128: 1:136 error: mismatched types: expected `&fn<no-bounds>(&&<VI5>) -> bool` but found `()` (expected fn but found ())
} assert_eq!(out, ~[5, 50, 35]);(100));ro; };
^~~~~~~~
<std-macros>:89:22: 89:47 error: binary operation == cannot be applied to type `std::iter::Filter<,&<VI5>,std::vec::VecIterator<,<VI5>>>`
<std-macros>:89 if !((given_val == expected_val) && (expected_val == given_val)) {
^~~~~~~~~~~~~~~~~~~~~~~~~
<std-macros>:83:4: 94:5 note: in expansion of assert_eq!
less-than-100.rs:1:141: 1:171 note: expansion site
<std-macros>:89:69: 89:78 error: mismatched types: expected `~[<VI9>]` but found `std::iter::Filter<,&<VI5>,std::vec::VecIterator<,<VI5>>>` (expected vector but found struct std::iter::Filter)
<std-macros>:89 if !((given_val == expected_val) && (expected_val == given_val)) {
^~~~~~~~~
<std-macros>:83:4: 94:5 note: in expansion of assert_eq!
less-than-100.rs:1:141: 1:171 note: expansion site
error: aborting due to 3 previous errors
fn main() {
let lt = |ro: int| { |lo: int| lo < ro; };
let num = [5, 500, 50, 101, 200, 35];
let out = num.iter().filter(lt(100));
assert_eq!(out, ~[5, 50, 35]);
}
@nielsle
Copy link
Copy Markdown

nielsle commented Oct 15, 2013

The following seems to work: (I found you on twitter and got some help on #rust)

fn main (){

    let num = ~[5, 500, 50, 101, 200, 35];
    let out = num.move_iter().filter( |& x| x < 100).to_owned_vec();

    assert_eq!(out, ~[5, 10, 35]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment