Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplexStream across tasks and closures
    text
    copied!<p>I'm having trouble with <a href="https://stackoverflow.com/questions/17490716/lifetimes-in-rust/17493553#17493553">lifetimes</a> and borrowed points. I've read the manual and borrowed pointer tutorial, but... I'm still stuck.</p> <p>Sketch of <code>main.rs</code></p> <pre><code>fn main() { let (db_child, repo_child):(DuplexStream&lt;~str, ~str&gt;, DuplexStream&lt;~str, ~str&gt;) = DuplexStream(); do spawn { slurp_repos(&amp;repo_child); } } </code></pre> <p>Sketch of <code>repos.rs</code></p> <pre><code>fn slurp_repos(chan: &amp;'static DuplexStream&lt;~str, ~str&gt;) { ... do request.begin |event| { ... chan.send(api_url); } } </code></pre> <p>When I compile these modules, main.rs has the following error:</p> <pre><code>main.rs:21:20: 21:31 error: borrowed value does not live long enough main.rs:21 slurp_repos(&amp;repo_child); ^~~~~~~~~~~ note: borrowed pointer must be valid for the static lifetime... main.rs:13:10: 1:0 note: ...but borrowed value is only valid for the block at 13:10 error: aborting due to previous error </code></pre> <p>I can't quite figure out how to declare my DuplexStreams lifetime static. Or perhaps this was the wrong way to go in the function type for slurp_repos.</p> <p>If you want to see the full context:</p> <ul> <li><a href="https://github.com/ozten/learning_rust/blob/b8e9d5bad6fbc3ad8fd9150c8fa739a9aaae5530/main.rs#L13-L21" rel="nofollow noreferrer">main.rs</a></li> <li><a href="https://github.com/ozten/learning_rust/blob/b8e9d5bad6fbc3ad8fd9150c8fa739a9aaae5530/repository_metadata_slurp.rs#L93-L126" rel="nofollow noreferrer">repos.rs</a></li> </ul>
 

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