[rust-dev] Swapping elements in a vec

Brian Anderson andersrb at gmail.com
Sun Feb 27 14:19:06 PST 2011


This works, but the "mutable 1" notation sure seems odd.

impure fn main() {
  let vec[mutable int] a = vec(mutable 1,2,3);
  let int t = a.(0);
  a.(0) = a.(1);
  a.(1) = t;
  log a.(0);
  log a.(1);
  check (a.(0) == 2);
  check (a.(1) == 1);
}


On Sun, Feb 27, 2011 at 4:51 PM, Peter Hull <peterhull90 at gmail.com> wrote:

> Is it possible to swap elements in a vec? I tried
>  let mutable vec[int] a = vec(1,2,3);
>  let int t = a.(0);
>  a.(0) = a.(1);
>  a.(1) = t;
> but rustboot says (quite rightly I suppose) that int is not mutable.
>
> Pete
> ps. hope you're not too disappointed I stuck to ASCII for my
> identifiers, what's Chinese for 'a' anyway?!?
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20110227/58480edd/attachment.html>


More information about the Rust-dev mailing list