]> git.dolda2000.com Git - kaka/rust-sdl-test.git/commitdiff
expect() with formatting -> unwrap_or_else()
authorTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 2 Jan 2021 18:00:18 +0000 (19:00 +0100)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 2 Jan 2021 18:02:10 +0000 (19:02 +0100)
Because with expect() the formatting will always be called, even when there is a value.

src/sprites.rs

index 57fc0a4eb4b0a05009ebc420fc3033b976cd686d..0de34689f90aec34d1a9e127d3e074627802353e 100644 (file)
@@ -23,6 +23,6 @@ impl SpriteManager {
     }
 
     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))
     }
 }