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 "owned" string that can only have one owner. If you move it (give away ownership) you can not use it anymore. The compiler verifies that.

This is why move_iter() consumes a vector (takes ownership), while iter() only gives you references (& pointers) to the elements.

This allows the memory to be freed when the owner disappears, without garbage collection or reference counting.


    ~~~
    let ports = do myvect.move_iter().map |s| {
         let (pport, cchan) = stream();
         do spawn {
             cchan.send(fun(s))
         }
         pport
    }.to_owned_vec();


There is still a problem because something (I guess the `do spawn
{...}`) is a "heap closure".

  * error: cannot move out of captured outer variable in a heap closure
      o cchan.send(fun(s))

I think that this error message is complaining because I'm trying to
move s, the ~str that the `do spawn {...}` closes over, to a new task.
And I'm not allowed to move it because it is apparently a heap closure.
Is there some other kind of closure that does work here? Or some way to
make this not a closure?

I’m not sure, but you may need to use spawn_with to move something into a task:

do spawn_with(s) |s| { ... }

--
Simon Sapin
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to