我正在按照这个教程来构建一个类似Rogue-like的游戏,我决定开始使用specs调度程序来更轻松地注册和执行系统。
为此,我在我的
为此,我在我的
State
结构中添加了一个Dispatcher
。
use rltk::{GameState, Rltk};
use specs::world::World;
use specs::Dispatcher;
pub struct State<'a, 'b> { // <-- Added new lifetime params here for dispacher
pub ecs: World,
pub dsp: Dispatcher<'a, 'b>,
}
但是当我尝试为它实现GameSate
特性时,遇到了问题:
impl<'a, 'b> GameState for State<'a, 'b> {
fn tick(&mut self, ctx: &mut Rltk) {
ctx.cls();
self.dsp.dispatch(&mut self.ecs);
self.ecs.maintain();
}
}
我遇到了以下错误:
error[E0478]: lifetime bound not satisfied
--> src/sys/state.rs:96:14
|
96 | impl<'a, 'b> GameState for State<'a, 'b> {
| ^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined on the impl at 96:6
--> src/sys/state.rs:96:6
|
96 | impl<'a, 'b> GameState for State<'a, 'b> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
error[E0478]: lifetime bound not satisfied
--> src/sys/state.rs:96:14
|
96 | impl<'a, 'b> GameState for State<'a, 'b> {
| ^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'b` as defined on the impl at 96:10
--> src/sys/state.rs:96:10
|
96 | impl<'a, 'b> GameState for State<'a, 'b> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
它希望生命周期 'a, 'b
能够长于 'static
,但我确信 'static
就是整个程序的生命周期,这似乎不可能实现。
我该如何解决这个问题?
'static
生命周期应该没问题。 - Thermatix