rust 为什么Bevy的特质界限不满足剑剑物理插件?

m1m5dgzv  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(156)

我一直在尝试运行这个最小的例子,以获得Rapier的物理工作Bevy

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
        .run();
}

但它失败了

error[E0277]: the trait bound `bevy_rapier2d::plugin::RapierPhysicsPlugin: Plugin` is not satisfied
   --> src/main.rs:8:21
    |
8   |         .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
    |          ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Plugin` is not implemented for `bevy_rapier2d::plugin::RapierPhysicsPlugin`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the following other types implement trait `Plugin`:
              AnimationPlugin
              AssetCountDiagnosticsPlugin<T>
              AssetPlugin
              AudioPlugin
              BloomPlugin
              CameraPlugin
              CameraProjectionPlugin<T>
              ColorMaterialPlugin
            and 44 others
note: required by a bound in `bevy::prelude::App::add_plugin`
   --> /home/techperson/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_app-0.9.0/src/app.rs:837:12
    |
837 |         T: Plugin,
    |            ^^^^^^ required by this bound in `bevy::prelude::App::add_plugin`

For more information about this error, try `rustc --explain E0277`.

预期行为如Rapier documentation中所述。
一些信息:

$ cargo version
cargo 1.66.0-beta.1 (7e484fc1a 2022-10-27)

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/techperson/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

beta-x86_64-unknown-linux-gnu (default)
rustc 1.66.0-beta.1 (e080cc5a6 2022-11-01)

Cargo.toml的相关部分:

[dependencies]
bevy = "0.9.0"
bevy_rapier2d = "0.18.0"

我尝试手动实现Plugin特征,但无法实现,因为它来自不同的机箱:

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
 --> src/main.rs:4:1
  |
4 | impl Plugin for RapierPhysicsPlugin {}
  | ^^^^^^^^^^^^^^^^-------------------
  | |               |
  | |               `bevy_rapier2d::plugin::RapierPhysicsPlugin` is not defined in the current crate
  | impl doesn't use only types from inside the current crate
  |
  = note: define and implement a trait or new type instead

For more information about this error, try `rustc --explain E0117`.

我还尝试了stablebetanightly工具链。betanightly失败并出现上述错误,stable失败是因为if-let语句不稳定。

goucqfw6

goucqfw61#

Bevy 0.9是一个extremely recent release,在写这篇文章的3天前,它对bevy内部做了相当多的修改,尤其是trait系统,这是一个在这个阶段不稳定的项目可以预料到的。
在接下来的几周里,大部分的生态系统都会升级,恢复到bevy 0.8,你现在应该没问题了。

qcbq4gxm

qcbq4gxm2#

我还没有真正测试它,只重新编译代码添加插件,并直接导致上述错误。但至少这(临时解决方案)防止错误发生(需要看看它多一点,但我已经用完了今天的时间):https://github.com/mariasiuvlad/bevy-game/pull/5/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R12
TL;DR:

bevy_rapier2d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.9" }

相关问题