我在生命周期和借来的积分方面遇到了麻烦。我已经阅读了手册和借用的指针教程,但是......我仍然被卡住了。
素描main.rs
fn main() {
let (db_child, repo_child):(DuplexStream<~str, ~str>, DuplexStream<~str, ~str>) = DuplexStream();
do spawn {
slurp_repos(&repo_child);
}
}
素描repos.rs
fn slurp_repos(chan: &'static DuplexStream<~str, ~str>) {
...
do request.begin |event| {
...
chan.send(api_url);
}
}
当我编译这些模块时, main.rs 有以下错误:
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
我不太清楚如何声明我的 DuplexStreams 生命周期静态。或者这可能是 slurp_repos 函数类型的错误方法。
如果您想查看完整的上下文: