use std::collections::HashMap; use sdl2::image::LoadTexture; use sdl2::render::Texture; use sdl2::render::TextureCreator; use sdl2::video::WindowContext; pub struct SpriteManager { texture_creator: TextureCreator, // can't make the lifetimes work when this is owned instead of borrowed textures: HashMap, } impl SpriteManager { pub fn new(texture_creator: TextureCreator) -> SpriteManager { SpriteManager { texture_creator, textures: HashMap::new(), } } pub fn load(&mut self, name: &str, file: &str) { self.textures.insert( name.to_string(), self.texture_creator.load_texture(file).unwrap(), ); } pub fn get(&self, name: &str) -> &Texture { self.textures .get(name) .unwrap_or_else(|| panic!("The sprite '{}' was not found", name)) } }