X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fsprites.rs;h=70de0c0a83ff06928d8c3b579eaf93c3d86ae92f;hb=a82a4d23f7e76f6899919fda31e7c29e68d319bb;hp=57fc0a4eb4b0a05009ebc420fc3033b976cd686d;hpb=fcbc5786908a32f68597961203d8c30e8a70c9ba;p=kaka%2Frust-sdl-test.git diff --git a/src/sprites.rs b/src/sprites.rs index 57fc0a4..70de0c0 100644 --- a/src/sprites.rs +++ b/src/sprites.rs @@ -7,7 +7,7 @@ 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<&'static str, Texture>, + textures: HashMap, } impl SpriteManager { @@ -18,11 +18,16 @@ impl SpriteManager { } } - pub fn load(&mut self, name: &'static str, file: &str) { - self.textures.insert(name, self.texture_creator.load_texture(file).unwrap()); + 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).expect(format!("The sprite '{}' was not found", name).as_str()) + self.textures + .get(name) + .unwrap_or_else(|| panic!("The sprite '{}' was not found", name)) } }