我一直在试着运行这个最小的例子,让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"

我try 手动实现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`.

我还try 了stablebetanightly工具链.betanightly失败,出现上述错误,stable失败,因为if-let条语句不稳定.

推荐答案

在 compose 本文时,Bevy 0.9是一个extremely recent release,3天前的版本.它对Bevy的内部 struct 有了很大的改变,特别是特征系统,就像在这个阶段一个不稳定的项目所预期的那样.

在接下来的几周里,生态系统的大部分将进行升级.回到BEVY 0.8,你现在应该没问题了.

Rust相关问答推荐

如何对字符串引用的引用向量进行排序,而不是对最外层的引用进行排序?

如何使用字符串迭代器执行查找?

Rust TcpStream不能在读取后写入,但可以在不读取的情况下写入.为什么?

这种获取-释放关系是如何运作的?

如何删除Mac Tauri上的停靠图标?

重写Rust中的方法以使用`&;mut self`而不是`mut self`

如何高效地将 struct 向量中的字段收集到单独的数组中

我们能确定Rust会优化掉Clone()吗?如果它会立即掉落?

程序在频道RX上挂起

Tokio';s io::用Cursor拆分<;Vec<;u8>>;赢得';t get the full writted data

&'a T 是否意味着 T: 'a?

Boxing 如何将数据从堆栈移动到堆?

将引用移动到线程中

为什么我们有两种方法来包含 serde_derive?

pyO3 和 Panics

push 方法是否取得所有权?

一个函数调用会产生双重borrow 错误,而另一个则不会

如何使用 rust bindgen 生成的 std_vector

Abortable:悬而未决的期货?

tokio async rust 的 yield 是什么意思?