summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-11 20:12:11 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-11 20:12:11 -0500
commitb8808fe47b8b2abd05989c7b1faabb29fabc0c07 (patch)
tree7671ee92d4ea5fed39a503d0b629d12d005b0514
parentdungeon: downcast! -> try_from! (diff)
downloadDungeonCrawl-b8808fe47b8b2abd05989c7b1faabb29fabc0c07.tar.gz
DungeonCrawl-b8808fe47b8b2abd05989c7b1faabb29fabc0c07.tar.bz2
DungeonCrawl-b8808fe47b8b2abd05989c7b1faabb29fabc0c07.zip
dungeon: rewrite const_pos!
-rw-r--r--dungeon/src/pos.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/dungeon/src/pos.rs b/dungeon/src/pos.rs
index b7a977c..59daaa2 100644
--- a/dungeon/src/pos.rs
+++ b/dungeon/src/pos.rs
@@ -32,18 +32,15 @@ macro_rules! try_from {
#[macro_export]
macro_rules! const_pos {
- ($x:expr, $y:expr) => {{
- assert!(
- $x < $crate::map::MAP_SIZE,
- "Positions must be smaller then MAP_SIZE"
- );
- assert!(
- $y < $crate::map::MAP_SIZE,
- "Positions must be smaller then MAP_SIZE"
- );
- const CONST_POS: Pos = unsafe { Pos::new_unchecked($x, $y) };
- CONST_POS
- }};
+ ($x:expr, $y:expr) => {
+ const {
+ const X: u16 = $x;
+ const Y: u16 = $y;
+ assert!(X < $crate::map::MAP_SIZE, "X must be smaller then MAP_SIZE");
+ assert!(Y < $crate::map::MAP_SIZE, "Y must be smaller then MAP_SIZE");
+ unsafe { $crate::pos::Pos::new_unchecked(X, Y) }
+ }
+ };
}
/// The `Direction` type represents a direction an entity