【问题标题】:Why are Bevy's Trait bounds not satisfied for the Rapier physics plugin?为什么 Bevy 的 Trait bounds 不满足 Rapier 物理插件?
【发布时间】:2022-11-16 13:51:21
【问题描述】:

我一直在尝试运行这个最小的例子来让 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 语句不稳定。

【问题讨论】:

    标签: rust bevy rapier rapier-2d


    【解决方案1】:

    Bevy 0.9extremely recent release,3 天前撰写本文时。它改变了很多内部结构,尤其是特质系统,正如现阶段不稳定项目所预期的那样。

    大多数生态系统将在接下来的几周内升级。恢复到 bevy 0.8,你现在应该没问题。

    【讨论】:

    猜你喜欢
    • 2021-08-08
    • 2019-12-23
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2012-06-20
    • 2021-12-04
    • 2017-12-13
    • 1970-01-01
    相关资源
    最近更新 更多