基本上,我需要包含一个结构VecDeque的State秒.我的代码到目前为止:
type State = [[bool]];
pub struct MyStruct {
queue: VecDeque<State>,
}
impl MyStruct {...}
Run Code Online (Sandbox Code Playgroud)
在编译这段代码时,我结束了
error: the trait `core::marker::Sized` is not implemented for the type `[[bool]]` [E0277]
note: `[[bool]]` does not have a constant size known at compile-time
Run Code Online (Sandbox Code Playgroud)
我想State在队列中根本不是好主意,所以我尝试了一个引用队列(这也适合我的应用程序).
type State = [[bool]];
pub struct MyStruct {
queue: VecDeque<&State>,
}
impl MyStruct {...}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,更奇怪的错误发生:
error: missing lifetime specifier [E0106]
Run Code Online (Sandbox Code Playgroud)
如何创建这样的结构,以便按照我上面的方式工作?我真的不是Rust专家.
基本问题是[[bool]] 毫无意义的. [bool]是动态大小的,你不能拥有一个动态大小的数组,所以这[[bool]]是不可能的.
目前还不完全清楚你要在这里完成什么.最明显的解决方案是使用Vec:
pub struct MyStruct {
queue: VecDeque<Vec<Vec<bool>>>,
}
Run Code Online (Sandbox Code Playgroud)
至于你的"更奇怪的错误",这表明你没有读过Rust Book,特别是有关Lifetimes的章节.为了编写包含借用指针的结构,您必须指定生命周期.
| 归档时间: |
|
| 查看次数: |
465 次 |
| 最近记录: |