Tec*_*son 5 rust bevy rapier-2d rapier
我一直在尝试运行这个最小的示例,以使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();
}
Run Code Online (Sandbox Code Playgroud)
它失败了:
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`.
Run Code Online (Sandbox Code Playgroud)
Rapier 文档中描述了预期的行为。
一些信息:
$ 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)
Run Code Online (Sandbox Code Playgroud)
相关部分Cargo.toml:
[dependencies]
bevy = "0.9.0"
bevy_rapier2d = "0.18.0"
Run Code Online (Sandbox Code Playgroud)
我尝试手动实现该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`.
Run Code Online (Sandbox Code Playgroud)
我还尝试过stable、beta和nightly工具链。beta并nightly因上述错误而失败,并stable因if-let语句不稳定而失败。
| 归档时间: |
|
| 查看次数: |
1300 次 |
| 最近记录: |