diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2023-06-01 14:46:36 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-06-01 14:46:36 +0200 |
| commit | dc7c6d43c77c2edb549f574188da8aff4ac0fba4 (patch) | |
| tree | 68fbbee7c881b83b6cf0f9f4e00516689244b7fd /lib | |
| parent | 117f9b7752120a629283f9cdcc3f50b622aa070b (diff) | |
| download | rust-dc7c6d43c77c2edb549f574188da8aff4ac0fba4.tar.gz rust-dc7c6d43c77c2edb549f574188da8aff4ac0fba4.zip | |
Slightly shrink `DefMap`
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/la-arena/src/lib.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/la-arena/src/lib.rs b/lib/la-arena/src/lib.rs index 1f8ef01a5bc..5107f294394 100644 --- a/lib/la-arena/src/lib.rs +++ b/lib/la-arena/src/lib.rs @@ -18,6 +18,18 @@ pub use map::{ArenaMap, Entry, OccupiedEntry, VacantEntry}; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct RawIdx(u32); +impl RawIdx { + /// Constructs a [`RawIdx`] from a u32. + pub const fn from_u32(u32: u32) -> Self { + RawIdx(u32) + } + + /// Deconstructs a [`RawIdx`] into the underlying u32. + pub const fn into_u32(self) -> u32 { + self.0 + } +} + impl From<RawIdx> for u32 { #[inline] fn from(raw: RawIdx) -> u32 { @@ -94,12 +106,12 @@ impl<T> fmt::Debug for Idx<T> { impl<T> Idx<T> { /// Creates a new index from a [`RawIdx`]. - pub fn from_raw(raw: RawIdx) -> Self { + pub const fn from_raw(raw: RawIdx) -> Self { Idx { raw, _ty: PhantomData } } /// Converts this index into the underlying [`RawIdx`]. - pub fn into_raw(self) -> RawIdx { + pub const fn into_raw(self) -> RawIdx { self.raw } } |
