358: add from impls for u32/usize r=nikomatsakis a=nikomatsakis

Make it easy to create an `Id`, especially from a `usize`

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
bors[bot] 2022-08-18 23:37:31 +00:00 committed by GitHub
commit 02a5fc0e3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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()