From: Tomas Wenström Date: Sat, 2 Jan 2021 18:37:52 +0000 (+0100) Subject: Use String instead of &str in struct X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=1e322944b05e76544fb6a5f541a517aedb2c4800;p=kaka%2Frust-sdl-test.git Use String instead of &str in struct It makes things a lot easier --- 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 {