This is the smallest thing I could get that reproduces my problem:
pub trait IoEventHandling {
fn add_key_callback(&mut self, callback : Box<dyn FnMut(&[KeyActionState])>);
}
pub struct KeyActionState;
type KeyEvent<'io> = Box<dyn FnMut(&[KeyActionState]) + 'io>;
struct Window<'io> {
key_callbacks: Vec<KeyEvent<'io>>,
}
// impl<'io> Window<'io> {
impl<'io> IoEventHandling for Window<'io> {
fn add_key_callback(&mut self, callback: KeyEvent<'io>) {
self.key_callbacks.push(callback);
}
}
struct PeripheralBureau<'io> {
window: Window<'io>,
}
impl<'io> PeripheralBureau<'io> {
fn window(&mut self) -> &mut Window<'io> {
&mut self.window
}
}
struct ECStorage;
impl ECStorage {
fn component_query<T>(&mut self) -> impl Iterator<Item = ()> {
std::iter::empty()
}
}
struct KeyBoardMotion;
fn move_user_controlled_entities<'io>(
ecs: &'io mut ECStorage,
io_context: &mut PeripheralBureau<'io>,
) {
io_context
.window()
.add_key_callback(Box::new(move |states| {
for motion in ecs.component_query::<KeyBoardMotion>() {}
}))
}
If you comment out impl<'io> IoEventHandling for Window<'io> { and uncomment the line above it it will work.
Why is implementing the trait breaking the code?