我想创建AtomicPtr一个切片,但我惊讶地发现我不能。
struct MyObject {
ptr: AtomicPtr<[u32]>
}
Run Code Online (Sandbox Code Playgroud)
产生错误:
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
--> src/lib.rs:4:5
|
4 | ptr: AtomicPtr<[u32]>
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[u32]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::sync::atomic::AtomicPtr`
Run Code Online (Sandbox Code Playgroud)
在Rust Playground上看到它
我个人不明白为什么会这样,但我可能会遗漏一些东西。这个限制有什么原因吗?是否有实现相同功能的解决方法?
| 归档时间: |
|
| 查看次数: |
201 次 |
| 最近记录: |