防锈寿命参数必须超过静态寿命

问题描述 投票:0回答:1

因此,我遵循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是整个程序的生存期。

我该如何解决?

rust static traits lifetime
1个回答
1
投票

['static要求实现者必须为'static

GameState

为了满足GameState生存期,您的类型不得包含任何短于'static的引用。因此,如果不能同时将pub trait GameState: 'static {...} 'static都设为'static,则唯一的选择就是不要将'a放在'b内。

© www.soinside.com 2019 - 2024. All rights reserved.