add from impls for u32/usize

This commit is contained in:
Niko Matsakis 2022-08-18 16:35:50 -04:00
parent 6fe5062548
commit 1c9c7280b7

View file

@ -38,6 +38,19 @@ impl Id {
}
}
impl From<u32> for Id {
fn from(n: u32) -> Self {
Id::from_u32(n)
}
}
impl From<usize> for Id {
fn from(n: usize) -> Self {
assert!(n < Id::MAX_USIZE);
Id::from_u32(n as u32)
}
}
impl From<Id> for u32 {
fn from(n: Id) -> Self {
n.as_u32()