Add a from_u32 function to EntityRef.

This eliminates the need for casting in common cases.
This commit is contained in:
Dan Gohman
2018-12-10 07:17:39 -08:00
parent b841652539
commit 68a13646f9

View File

@@ -100,6 +100,13 @@ macro_rules! entity_impl {
} }
impl $entity { 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`. /// Return the underlying index value as a `u32`.
#[allow(dead_code)] #[allow(dead_code)]
pub fn as_u32(self) -> u32 { pub fn as_u32(self) -> u32 {