Revert "do not expose that RawId is stored in a u32"

This reverts commit 9b106e9279.
This commit is contained in:
Niko Matsakis 2019-03-31 07:23:39 -03:00
parent d6934ac247
commit 4402338908

View file

@ -2,8 +2,8 @@ use std::fmt;
use std::num::NonZeroU32;
/// 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
/// own devising. For more information about interned keys, see [the
/// a newtype'd u32. Typically, it is wrapped in a type of your own
/// devising. For more information about interned keys, see [the
/// interned key RFC][rfc].
///
/// # Creating a `RawId`
@ -18,23 +18,16 @@ use std::num::NonZeroU32;
/// 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
/// 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;
/// let raw_id = RawId::from(22_u32);
/// let value = raw_id.as_usize();
/// assert_eq!(value, 22);
/// ```
///
/// ```
/// # use salsa::RawId;
/// let raw_id = RawId::from(22_u32);
/// let value = usize::from(raw_id);
/// let value = u32::from(raw_id);
/// 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.
///
/// ```
/// # 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 {
(self.value.get() - 1) as usize
self.as_u32() as usize
}
}
impl From<RawId> for u32 {
fn from(raw: RawId) -> u32 {
raw.as_u32()
}
}