Thank you, I appreciate all the good feedback!

On Tue, Feb 26, 2013 at 11:56 AM, Niko Matsakis <[email protected]> wrote:

> Use vec::filtered().  vec::filter() works only on ~[T] and consumes its
> argument (so you cannot use it again) and vec::filtered() does not. This
> naming convention is probably too subtle and is also not entirely
> consistent across vec functions.
>
>
>
> Niko
>
>   Peter Ronnquist <[email protected]>
>  February 25, 2013 7:20 AM
> I'm having troubles to use vec::filter() when pattern matching a vector:
>
> fn main() {
>
> let objs = ~[1, 3, 2];
>
> fn isClose(a: int, b: int)-> bool {
> if (a-b <1) {true} else {false}
> }
> match objs {
> // Construct new integer vector that contains integers that
> are similar to the head.
> [head, ..tail] => vec::filter( tail, |obj| isClose(head, *obj)) ,
> [] => ~[]
> };
> }
>
> rustc tail_test.rs
> tail_test.rs:11:39: 11:43 error: mismatched types: expected `~[<V7>]`
> but found `&/[<VI2>]` ([] storage differs: expected ~ but found &)
> tail_test.rs:11 [head, ..tail] => vec::filter( tail, |obj|
> isClose(head, *obj)) ,
> ^~~~
> $ rustc -v
> rustc 0.6 (b26d434 2013-02-24 10:57:16 -0800)
> host: x86_64-unknown-linux-gnu
>
> It seems like tail is a & type and not a ~ that I expected.
> Any thoughts on this?
>
> Thanks in advance,
> Peter
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>

<<compose-unknown-contact.jpg>>

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to