I'm having trouble with lifetimes and borrowed points. I've read the manual and borrowed pointer tutorial, but... I'm still stuck.
Sketch of main.rs
fn main() {
let (db_child, repo_child):(DuplexStream<~str, ~str>, DuplexStream<~str, ~str>) = DuplexStream();
do spawn {
slurp_repos(&repo_child);
}
}
Sketch of repos.rs
fn slurp_repos(chan: &'static DuplexStream<~str, ~str>) {
...
do request.begin |event| {
...
chan.send(api_url);
}
}
When I compile these modules, main.rs has the following error:
main.rs:21:20: 21:31 error: borrowed value does not live long enough
main.rs:21 slurp_repos(&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
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.
If you want to see the full context: