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 57fc0a4..0de3468 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))
     }
 }