expect() with formatting -> unwrap_or_else()
[kaka/rust-sdl-test.git] / src / sprites.rs
index 82dd6dc..0de3468 100644 (file)
@@ -5,13 +5,13 @@ use sdl2::render::Texture;
 use sdl2::render::TextureCreator;
 use sdl2::video::WindowContext;
 
-pub struct SpriteManager<'canvas> {
-    texture_creator: &'canvas TextureCreator<WindowContext>, // can't make the lifetimes work when this is owned instead of borrowed
-    textures: HashMap<&'static str, Texture<'canvas>>,
+pub struct SpriteManager {
+    texture_creator: TextureCreator<WindowContext>, // can't make the lifetimes work when this is owned instead of borrowed
+    textures: HashMap<&'static str, Texture>,
 }
 
-impl<'canvas> SpriteManager<'canvas> {
-    pub fn new(texture_creator: &'canvas TextureCreator<WindowContext>) -> SpriteManager<'canvas> {
+impl SpriteManager {
+    pub fn new(texture_creator: TextureCreator<WindowContext>) -> SpriteManager {
         SpriteManager {
             texture_creator,
             textures: HashMap::new(),
@@ -23,6 +23,6 @@ impl<'canvas> SpriteManager<'canvas> {
     }
 
     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))
     }
 }