【问题标题】:Why is the trait not implemented?为什么特征没有实现?
【发布时间】:2020-12-04 15:06:59
【问题描述】:

我想尝试使用amethyst_physics 库来制作游戏。 (呃) 我遵循了示例,但不知怎的我不工作:

use amethyst::GameDataBuilder;
use amethyst_physics::{PhysicsBundle};
use amethyst_nphysics::NPhysicsBackend;

fn main() -> amethyst::Result<()> {
    amethyst::start_logger(Default::default());

    let game_data = GameDataBuilder::default()
        .with_bundle(
            PhysicsBundle::<f32, NPhysicsBackend>::new()
        )
    ;
    Ok(())
}

错误:

the trait bound `amethyst_physics::PhysicsBundle<'_, '_, f32, amethyst_nphysics::NPhysicsBackend>: amethyst::amethyst_core::SystemBundle<'_, '_>` is not satisfied
the trait `amethyst::amethyst_core::SystemBundle<'_, '_>` is not implemented for `amethyst_physics::PhysicsBundle<'_, '_, f32, amethyst_nphysics::NPhysicsBackend>`

Here 就是一个例子。

我做错了什么?

【问题讨论】:

  • 我尝试运行完全相同的代码,包括您提到的板条箱。有很多“使用未声明的板条箱或模块”。如果您添加一个可重复的示例以便读者可以尝试您所说的内容,那将是一个好主意。
  • @Mihir 我运行它没有问题,除了上面提到的预期错误。编辑:嗯,另外你必须将板条箱添加到你的 Cargo.toml
  • 连编译都没有怎么运行?
  • 我的意思是运行编译仅在预期错误时中断。我的错。
  • 我让它在本地运行时出现同样的错误。 Cargo.toml amethyst = { version = "0.15.3", features = ["empty"] } amethyst_nphysics = "0.2.0" amethyst_physics = "0.2.0"

标签: rust traits amethyst


【解决方案1】:

这似乎是一个错误。它使用 amethyst 版本 0.15.1 但不是 0.15.3 成功编译。在补丁更改期间不会出现这样的回归。

amethyst 使用 amethyst_core 版本 0.15.3(其中定义了 SystemBundle)但 amethyst_physics 使用 amethyst_core 版本 0.10.1。

我已在紫水晶存储库中提交了issue


将此作为解决方法:

amethyst = { version = ">=0.15.0, <0.15.3", features = ["empty"] } 

【讨论】:

  • 在我看来这仍然是一个编译器错误,因为完全不清楚为什么它无法编译。
  • Rust 编译器已经提交了许多问题,要求在这种情况下提供更好的诊断错误消息。
  • 所以你认为编译器拒绝代码是正确的,应该只打印一个更好的诊断?这是可能的,虽然我看不出代码有什么问题,而且在我看来编译器应该接受它。
  • @SvenMarnach 是的,PhysicsBundle 没有实现with_bundle() 期望的SystemBundle 版本(使用amethyst 版本0.15.3 时)。与Why is a trait not implemented for a type that clearly has it implemented? 存在相同的版本兼容性问题
猜你喜欢
  • 1970-01-01
  • 2018-05-24
  • 2020-03-02
  • 2021-07-18
  • 2023-03-29
  • 2019-12-08
  • 2017-02-14
  • 1970-01-01
相关资源
最近更新 更多