Rust 为什么编译器会产生一个错误";处理时检测到循环…“;?
在上下文中,我使用Vulkano库制作一个游戏,所以我省略了所有Vulkano导入。我试图使用Rust 为什么编译器会产生一个错误";处理时检测到循环…“;?,rust,traits,vulkan,Rust,Traits,Vulkan,在上下文中,我使用Vulkano库制作一个游戏,所以我省略了所有Vulkano导入。我试图使用render()函数渲染我的世界,但我对错误感到困惑,因为我没有将world.rs中的任何实现引用到mesh.rs。我现在才开始使用锈菌几个月,所以我可能仍然对这些特性和东西感到困惑 项目源目录 src - main.rs // imports all the module file in the directory - mesh.rs // does not import `world.r
render()
函数渲染我的世界,但我对错误感到困惑,因为我没有将world.rs
中的任何实现引用到mesh.rs
。我现在才开始使用锈菌几个月,所以我可能仍然对这些特性和东西感到困惑
项目源目录
src
- main.rs // imports all the module file in the directory
- mesh.rs // does not import `world.rs` module
- world.rs // imports the `mesh.rs` module
- ...
网状物
pub属性网格{
类型顶点;
fn vert_data(&self,texture:&TextureAtlas,position:[f32;3])->Vec;//返回顶点数据
fn ind_data(&self,index:u32)->Vec;//返回索引数据
}
pub结构多维数据集{
顶部:[u16;2],
底部:[u16;2],
左:[u16;2],
右:[u16;2],
正面:[u16;2],
背面:[u16;2],
}
impl立方体{
/* ... */
}
立方体的impl网格{
/* ... */
}
我检查了world.rs
中的其他导入,但没有一个重新导入world.rs
世界杯
使用板条箱::网格::立方体;
使用板条箱::网::网;
酒吧结构世界{
名称:String,
区块:Vec,
}
impl世界{
pub fn渲染(设备:Arc、txtr:&TextureAtlas)->(Arc、Arc){
}
/* ... */
}
错误:
error[E0391]: cycle detected when processing `world::<impl at src\world.rs:24:1: 88:2>::render`
--> src\world.rs:34:5
|
34 | pub fn render(device: Arc<Device>, txtr: &TextureAtlas) -> (Arc<CpuAccessibleBuffer<[dyn Mesh<Vertex=CubeVtx>]>>, Arc<CpuAccessibleBuffer<[_]>>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires processing `world::<impl at src\world.rs:24:1: 88:2>::render`...
--> src\world.rs:34:5
|
34 | pub fn render(device: Arc<Device>, txtr: &TextureAtlas) -> (Arc<CpuAccessibleBuffer<[dyn Mesh<Vertex=CubeVtx>]>>, Arc<CpuAccessibleBuffer<[_]>>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires processing `mesh::Cube`...
--> src\mesh.rs:31:1
|
31 | pub struct Cube {
| ^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires processing `world::<impl at src\world.rs:24:1: 88:2>::render`, completing the cycle
note: cycle used when collecting item types in module `world`
--> src\main.rs:50:1
|
50 | mod world;
| ^^^^^^^^^^
错误[E0391]:处理“世界:::渲染”时检测到循环`
-->src\world.rs:34:5
|
34 | pub fn渲染(设备:Arc、txtr:&TextureAtlas)->(Arc、Arc){
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
注意:…这需要处理“世界:::呈现”。。。
-->src\world.rs:34:5
|
34 | pub fn渲染(设备:Arc、txtr:&TextureAtlas)->(Arc、Arc){
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
注意:…需要处理“网格::立方体”。。。
-->src\mesh.rs:31:1
|
31 | pub结构立方体{
| ^^^^^^^^^^^^^^^
=注:…这需要计算此板条箱中物品的差异。。。
=注意:…这同样需要处理“world:::render”,完成循环
注意:在“世界”模块中收集项目类型时使用的周期`
-->src\main.rs:50:1
|
50 |现代世界;
| ^^^^^^^^^^
我怀疑这可能与traitMesh
有关
我试图删除
目标
目录,并分离网格
的实现,以分离文件,只保留原始文件中的特征。因此,我发现自己对Rust的复杂特征系统非常幼稚。唯一需要做的更改是在关联类型上添加一个静态
生命周期>Vertex
,解决了错误显示为循环引用这一事实所带来的困惑
pub trait Mesh {
type Vertex: 'static;
fn vert_data(&self, texture: &TextureAtlas, position: [f32; 3]) -> Vec<Self::Vertex>; // returns the vertex data
fn ind_data(&self, index: u32) -> Vec<u32>; // returns the index data
}
pub属性网格{
类型:静态;
fn vert_data(&self,texture:&TextureAtlas,position:[f32;3])->Vec;//返回顶点数据
fn ind_data(&self,index:u32)->Vec;//返回索引数据
}
因此,我发现自己对Rust的复杂特征系统非常幼稚。我唯一要做的改变是在关联类型顶点上添加一个静态生存期,这解决了一个问题,这个问题确实混淆了错误显示为循环引用的事实
pub trait Mesh {
type Vertex: 'static;
fn vert_data(&self, texture: &TextureAtlas, position: [f32; 3]) -> Vec<Self::Vertex>; // returns the vertex data
fn ind_data(&self, index: u32) -> Vec<u32>; // returns the index data
}
pub属性网格{
类型:静态;
fn vert_data(&self,texture:&TextureAtlas,position:[f32;3])->Vec;//返回顶点数据
fn ind_data(&self,index:u32)->Vec;//返回索引数据
}
我发现您必须将关联类型设置为静态。好的,将您的调查结果生成答案。我发现您必须将关联类型设置为静态。好的,将您的调查结果生成答案。