From 68a13646f9e5b46e402f2a8a77d720317d0d3399 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 10 Dec 2018 07:17:39 -0800 Subject: [PATCH] Add a from_u32 function to EntityRef. This eliminates the need for casting in common cases. --- lib/entity/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/entity/src/lib.rs b/lib/entity/src/lib.rs index e445c0d8a4..e86ea0d8fd 100644 --- a/lib/entity/src/lib.rs +++ b/lib/entity/src/lib.rs @@ -100,6 +100,13 @@ macro_rules! entity_impl { } impl $entity { + /// Return the underlying index value as a `u32`. + #[allow(dead_code)] + pub fn from_u32(x: u32) -> Self { + debug_assert!(x < $crate::__core::u32::MAX); + $entity(x) + } + /// Return the underlying index value as a `u32`. #[allow(dead_code)] pub fn as_u32(self) -> u32 {