rust/lib-hwengine-future/src/ai/ammo.rs
branchtransitional_engine
changeset 16082 85d7d6b71087
parent 16078 db18f1a30b0c
--- a/rust/lib-hwengine-future/src/ai/ammo.rs	Thu Dec 19 14:18:55 2024 +0100
+++ b/rust/lib-hwengine-future/src/ai/ammo.rs	Tue Dec 31 15:18:18 2024 +0100
@@ -63,3 +63,15 @@
     Sentry, // 60
     Count,
 }
+
+impl TryFrom<usize> for AmmoType {
+    type Error = &'static str;
+
+    fn try_from(value: usize) -> Result<Self, Self::Error> {
+        if value < Self::Count as usize {
+            Ok(unsafe { std::mem::transmute(value) })
+        } else {
+            Err("Invalid ammo type")
+        }
+    }
+}