Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm unable to test, but I guess the solution is to move the <code>repo_child</code> stream into <code>slurp_repos</code>, that is:</p> <pre><code>fn main() { let (db_child, repo_child) = DuplexStream(); do spawn { slurp_repos(repo_child); } } fn slurp_repos(chan: DuplexStream&lt;~str, ~str&gt;) { ... do request.begin |event| { ... chan.send(api_url); } } </code></pre> <p>By moving the whole endpoint, it allows it to be transferred across tasks (because a <code>DuplexStream</code> is <code>Send</code>able). Also, note that sharing (what the use of a references allows) the endpoint of a basic bidirectional stream (which is what <code>DuplexStream</code> is) doesn't really make sense: there can only be one person at each end of a telephone.</p> <p>The error message about <code>repo_child</code> not living long enough is because the type of <code>slurp_repos</code> requires something that is <code>'static</code> i.e. lasts for the whole lifetime of the program, but <code>repo_child</code> definitely doesn't: it is local to a function.</p> <p>The reason the compiler tells you to put <code>'static</code> on <code>slurp_repos</code>, is because the only <code>Send</code>able reference is one with this lifetime. This restriction is required because you could have the owning task finish before the borrowing task does, and then destroy/deallocate the reference, leaving a dangling pointer; in diagrams:</p> <pre><code>start program/call main | v allocate repo_child | v spawn -----------------&gt; slurp_repos(chan = &amp;repo_child) | | v v finish do things with the chan reference to repo_child | | v v deallocate repo_child general work ... | v do more things with chan: oops, already freed; use-after-free bug </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload