From 1e322944b05e76544fb6a5f541a517aedb2c4800 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sat, 2 Jan 2021 19:37:52 +0100 Subject: [PATCH] Use String instead of &str in struct It makes things a lot easier --- src/game/app.rs | 2 +- src/sprites.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/app.rs b/src/game/app.rs index e1fafdc..50acaa1 100644 --- a/src/game/app.rs +++ b/src/game/app.rs @@ -48,7 +48,7 @@ impl App { } } - pub fn load_sprites(&mut self, sprites: &[(&'static str, &str)]) { + pub fn load_sprites(&mut self, sprites: &[(&str, &str)]) { for (name, file) in sprites { self.sprites.load(name, file); } diff --git a/src/sprites.rs b/src/sprites.rs index 0de3468..631f6ce 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,8 +18,8 @@ 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 { -- 2.11.0