[rust-dev] Fwd: Swapping elements in a vec

Peter Hull peterhull90 at gmail.com
Mon Feb 28 00:42:49 PST 2011


(sorry, sent this directly to Graydon instead of to the list)
On Sun, Feb 27, 2011 at 10:19 PM, Graydon Hoare <graydon at mozilla.com> wrote:
> Yeah. You want vec[mutable int]. We'll probably wind up with a 'swap'
> primitive at some point down the line when unique ownership and move
> semantics are more thoroughly worked out.
Thanks. To be more concrete, I was trying to write an iterator to
generate all permutations of a vec:
iter combinations[T](&vec[T] els) -> vec[T]
by
1. Making a mutable copy of els
2. Performing a sequence of swaps on my copy
3. 'put'ting a copy of each one
I have a feeling maybe I don't understand mutability now - in code like
let int i = 0;
i = i + 1;
Why doesn't i have to be mutable int?

> No need for this. We have a clear conduct guideline about insulting and
> baiting speech. Please refrain from it in the future.
Noted.

Pete


More information about the Rust-dev mailing list