rust - `T : ' static`是什么意思?

标签 rust

对限制的正确理解是什么T : 'static ? 据我了解,这意味着“任何实现 T 的东西都不应该直接或间接具有引用/指针”。我问这个问题是因为我曾经认为这意味着任何实现 T 的东西都应该在应用程序的整个生命周期中存在,但现在这样的解释对我来说看起来是错误的。

最佳答案

你的新理解是正确的。 T: 'static 表示 T 不包含生命周期,或者可能在整个程序中存在,但并非必须如此。

另请参阅Common Lifetime Misconceptions: if T: 'static then T must be valid for the entire program .

例如,String: 'static holds ,但是您可以随时删除String,并且您无法再访问它。只是,如果我有一个String并且我丢弃它,我可以永远持有它,而不必担心它会在我背后失效,因为,比如说,底层存储被释放。

关于rust - `T : ' static`是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72084162/

相关文章:

rust - libgreen 怎么了?

indexing - 使用生命周期实现索引特征

c++ - Rust 中的侵入式算法等价物

rust - include_bytes 的运行时成本是多少!或包含_str?

rust - FnOnce 内部枚举 : cannot move out of borrowed content

rust - 按索引修改字符串中的字符

plugins - 如何从 ConstVal 中取出一个元组?

mongodb - 如何将actix_web Json存储到mongodb?

docker - 为什么 setuid 被丢弃在 Alpine 容器中的 execve 上?

rust - Rust 如何尊重 Copy 特性?