我一直在尝试运行这个最小的例子,以获得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`.
我还尝试了stable
、beta
和nightly
工具链。beta
和nightly
失败并出现上述错误,stable
失败是因为if-let
语句不稳定。
2条答案
按热度按时间goucqfw61#
Bevy
0.9
是一个extremely recent release,在写这篇文章的3天前,它对bevy内部做了相当多的修改,尤其是trait系统,这是一个在这个阶段不稳定的项目可以预料到的。在接下来的几周里,大部分的生态系统都会升级,恢复到bevy
0.8
,你现在应该没问题了。qcbq4gxm2#
我还没有真正测试它,只重新编译代码添加插件,并直接导致上述错误。但至少这(临时解决方案)防止错误发生(需要看看它多一点,但我已经用完了今天的时间):https://github.com/mariasiuvlad/bevy-game/pull/5/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R12
TL;DR: