I have clear instruction from Rust pre-compile analyzer telling me:
&mut Sprite<Texture<Resources>>
Go to [Sprite](#) | [Texture](#) | [Resources](#)
explicit lifetime required in the type of `sprite_hash`
lifetime `'a` requiredrustc(E0621)
main.rs(38, 32): add explicit lifetime `'a` to the type of `sprite_hash`
[Peek Problem (Alt+F8)](#)
No quick fixes available
I know I need to apply a lifetime to the type of 'sprite_hash' but I don't see how to do it. Please advise.
Here's the code: (the return var 'sprite' is what's underlined in red in VSCode)
fn get_sprite<'a>(sprite_hash: &mut HashMap<Point, SpriteID>, piece_type: ChessPiece, piece_position: &Point) -> &'a mut Sprite<Texture<gfx_device_gl::Resources>> {
let sprite: &mut Sprite<Texture<gfx_device_gl::Resources>>;
match sprite_hash.get_mut(piece_position) {
Some(structure) => {
if structure.sprite_piecetype == ChessPiece::BlackBishop {
println!("BlackBishop");
}
sprite = &mut structure.sprite_image_instance;
sprite.set_position(piece_position.top_left_x as f64, piece_position.top_left_y as f64);
println!("Made it");
},
_ => println!("No piece found."),
}
sprite
}