2.10.3 添加 'static 约束的建议
1分钟内可阅读完
译文 · 基于 Learning Rust
添加 ‘static 约束的建议
原文链接: https://quinedot.github.io/rust-learning/c-static.html
编译器在这方面正在逐渐改进,但当它建议使用 &'static 或某个生命周期需要比 'static 活得更久时,它通常实际上意味着以下之一:
- 你处于不允许非
'static引用和其他非static类型的上下文中 - 你应该在某处添加生命周期参数
与其自己编造例子,我直接链接到这个 issue。 虽然已关闭,但其中一些示例仍有改进空间。