[rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Hi, I have a ~[~str]. I have code that will turn a ~str into a Portuint. I want to end up with a [Portuint]. (or ~ or @ or whatever. I just want to be able to iterate over the Ports later.) Since I'm not sure what looping construct to use, I tried with a for-each loop. ~~~ let ports = for s in

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Scott Lawrence
I would think: let ports = do myvect.iter().map { |e| something(e) } On Sat, 2 Nov 2013, Leah Hanson wrote: Hi, I have a ~[~str]. I have code that will turn a ~str into a Portuint. I want to end up with a [Portuint]. (or ~ or @ or whatever. I just want to be able to iterate over the Ports

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Thanks, Scott, I think that's closer. However, now I'm having trouble with my pointer types. Using the element inside a spawn means that I need to capture the owned string in the right way so that the compiler allows me to give it to the other task. This version: ~~~ let ports = do

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Brendan Zabarauskas
You’re trying to move the ~strs out of the vector. You’ll need to use `move_iter`: ~~~ let ports = do myvect.move_iter().map |s| { let (pport, cchan) = stream(); do spawn { cchan.send(fun(s)) } pport }.to_owned_vec(); ~~~ Also note the use of `to_owned_vec`. `map` lazily

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Leah Hanson
Thanks, Brendan. :) You’re trying to move the ~strs out of the vector. You’ll need to use `move_iter`: Is this moving about moving memory around or about promising the compiler that I won't use those elements of the vector again? ~~~ let ports = do myvect.move_iter().map |s| { let

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Tim Kuehn
Instead of `do spawn` try `do spawn_with(s) |s| { ... }`. Then the closure won't close over s, but rather take it as an argument, allowing it to move it out. Cheers On Sat, Nov 2, 2013 at 5:05 PM, Leah Hanson astriea...@gmail.com wrote: Thanks, Brendan. :) You’re trying to move the ~strs

Re: [rust-dev] How would you map one vector to a vector of a different element type?

2013-11-02 Thread Simon Sapin
Le 02/11/2013 21:05, Leah Hanson a écrit : Thanks, Brendan. :) You’re trying to move the ~strs out of the vector. You’ll need to use `move_iter`: Is this moving about moving memory around or about promising the compiler that I won't use those elements of the vector again? ~str is an