I wonder if vec::filter ought to be rewritten to take &[] rather than ~[].
It's possible this decision was just a legacy one, but I'm not sure if
there are technical obstacles.


On Mon, Feb 25, 2013 at 7:20 AM, Peter Ronnquist
<[email protected]>wrote:

> 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
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to