diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-07 09:11:12 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-07 09:11:12 -0500 |
| commit | a8e9027b4af9dfd5ac68ebcf2253d1330e3d8cc6 (patch) | |
| tree | d30a2c5d32870994204d3ac3603afefeb0148138 /graphics | |
| parent | graphics: update some doc strings (diff) | |
| download | DungeonCrawl-a8e9027b4af9dfd5ac68ebcf2253d1330e3d8cc6.tar.gz DungeonCrawl-a8e9027b4af9dfd5ac68ebcf2253d1330e3d8cc6.tar.bz2 DungeonCrawl-a8e9027b4af9dfd5ac68ebcf2253d1330e3d8cc6.zip | |
graphics: update get_key_pressed to use try_borrow_mut instead of borrow_mut
Diffstat (limited to 'graphics')
| -rw-r--r-- | graphics/src/lib.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 9917a94..81ac16e 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -109,7 +109,12 @@ impl Window { /// Get the last key pressed pub fn get_key_pressed(&self) -> Option<KeyCode> { - self.handle.borrow_mut().get_key_pressed() + // We dont want to require a mutable reference + // to read the last key pressed + self.handle + .try_borrow_mut() + .ok() + .and_then(|mut h| h.get_key_pressed()) } /// Get audio data for the window |