Vsync instead of fps + print display modes
[kaka/rust-sdl-test.git] / src / sprites.rs
index 82dd6dc..631f6ce 100644 (file)
@@ -5,24 +5,24 @@ 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<String, 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(),
         }
     }
 
-    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))
     }
 }