mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 12:56:33 +00:00
Change the constructor of salsa::Id
to const fn
This commit is contained in:
parent
67d290dc26
commit
5718229882
1 changed files with 6 additions and 4 deletions
|
@ -26,14 +26,16 @@ impl Id {
|
|||
/// but it can be useful if you are using the type as a general
|
||||
/// purpose "identifier" internally.
|
||||
#[track_caller]
|
||||
pub fn from_u32(x: u32) -> Self {
|
||||
assert!(x < Self::MAX_U32);
|
||||
pub const fn from_u32(x: u32) -> Self {
|
||||
Id {
|
||||
value: NonZeroU32::new(x + 1).unwrap(),
|
||||
value: match NonZeroU32::new(x + 1) {
|
||||
Some(v) => v,
|
||||
None => panic!("given value is too large to be a `salsa::Id`"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_u32(self) -> u32 {
|
||||
pub const fn as_u32(self) -> u32 {
|
||||
self.value.get() - 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue