mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
Revert "do not expose that RawId is stored in a u32"
This reverts commit 9b106e9279
.
This commit is contained in:
parent
d6934ac247
commit
4402338908
1 changed files with 31 additions and 13 deletions
|
@ -2,8 +2,8 @@ use std::fmt;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
/// The "raw-id" is used for interned keys in salsa -- it is basically
|
/// The "raw-id" is used for interned keys in salsa -- it is basically
|
||||||
/// a newtype'd integer. Typically, it is wrapped in a type of your
|
/// a newtype'd u32. Typically, it is wrapped in a type of your own
|
||||||
/// own devising. For more information about interned keys, see [the
|
/// devising. For more information about interned keys, see [the
|
||||||
/// interned key RFC][rfc].
|
/// interned key RFC][rfc].
|
||||||
///
|
///
|
||||||
/// # Creating a `RawId`
|
/// # Creating a `RawId`
|
||||||
|
@ -18,23 +18,16 @@ use std::num::NonZeroU32;
|
||||||
/// assert_eq!(raw_id1, raw_id2);
|
/// assert_eq!(raw_id1, raw_id2);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Converting to a usize
|
/// # Converting to a u32 or usize
|
||||||
///
|
///
|
||||||
/// Normally, there should be no need to access the underlying integer
|
/// Normally, there should be no need to access the underlying integer
|
||||||
/// in a `RawId`. But if you do need to do so, you can convert to a
|
/// in a `RawId`. But if you do need to do so, you can convert to a
|
||||||
/// `usize` using the `as_usize` method or the `From` impl.
|
/// `usize` using the `as_u32` or `as_usize` methods or the `From` impls.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use salsa::RawId;
|
/// # use salsa::RawId;
|
||||||
/// let raw_id = RawId::from(22_u32);
|
/// let raw_id = RawId::from(22_u32);
|
||||||
/// let value = raw_id.as_usize();
|
/// let value = u32::from(raw_id);
|
||||||
/// assert_eq!(value, 22);
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// # use salsa::RawId;
|
|
||||||
/// let raw_id = RawId::from(22_u32);
|
|
||||||
/// let value = usize::from(raw_id);
|
|
||||||
/// assert_eq!(value, 22);
|
/// assert_eq!(value, 22);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -72,9 +65,34 @@ impl RawId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert this raw-id into a u32 value.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use salsa::RawId;
|
||||||
|
/// let raw_id = RawId::from(22_u32);
|
||||||
|
/// let value = raw_id.as_usize();
|
||||||
|
/// assert_eq!(value, 22);
|
||||||
|
/// ```
|
||||||
|
pub fn as_u32(self) -> u32 {
|
||||||
|
self.value.get() - 1
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert this raw-id into a usize value.
|
/// Convert this raw-id into a usize value.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use salsa::RawId;
|
||||||
|
/// let raw_id = RawId::from(22_u32);
|
||||||
|
/// let value = raw_id.as_usize();
|
||||||
|
/// assert_eq!(value, 22);
|
||||||
|
/// ```
|
||||||
pub fn as_usize(self) -> usize {
|
pub fn as_usize(self) -> usize {
|
||||||
(self.value.get() - 1) as usize
|
self.as_u32() as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RawId> for u32 {
|
||||||
|
fn from(raw: RawId) -> u32 {
|
||||||
|
raw.as_u32()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue