因此,我遵循this tutorial构建类似流氓的软件,因此我决定开始使用specs调度程序来简化系统的注册和执行。
为此,我向Dispatcher
结构中添加了Dispatcher
:
State
但是当我尝试实现
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
我收到这些错误:
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
:
GameState
为了满足GameState
生存期,您的类型不得包含任何短于'static
的引用。因此,如果不能同时将pub trait GameState: 'static {...}
和'static
都设为'static
,则唯一的选择就是不要将'a
放在'b
内。