diff options
| author | Thomas Voss <mail@thomasvoss.com> | 2026-03-12 20:13:16 +0100 |
|---|---|---|
| committer | Thomas Voss <mail@thomasvoss.com> | 2026-03-12 20:13:16 +0100 |
| commit | 9263d4114f449421f57dbc9c597684a2ce7fcaed (patch) | |
| tree | 4345a8d644d87ef83a11663a70225d4334dae5c9 /oryxc/src/prelude.rs | |
| parent | c77b9644712f93f529309751e06d59e22dbb5090 (diff) | |
Create a macro for generating ID types
Diffstat (limited to 'oryxc/src/prelude.rs')
| -rw-r--r-- | oryxc/src/prelude.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/oryxc/src/prelude.rs b/oryxc/src/prelude.rs index 4e36f33..03dbc07 100644 --- a/oryxc/src/prelude.rs +++ b/oryxc/src/prelude.rs @@ -6,20 +6,25 @@ use std::fmt::{ use crate::hashtrie::HTrie; -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct FileId(pub usize); - -#[repr(transparent)] -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct SymbolId(pub u32); +macro_rules! mkidtype { + ($name:ident) => { + #[repr(transparent)] + #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] + pub struct $name(pub u32); + impl $name { + #[allow(dead_code)] + pub const INVALID: Self = Self(u32::MAX); + } + }; +} -#[repr(transparent)] -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct ScopeId(pub usize); +mkidtype!(FileId); +mkidtype!(ScopeId); +mkidtype!(SymbolId); +mkidtype!(TypeId); impl ScopeId { pub const GLOBAL: Self = Self(0); - pub const INVALID: Self = Self(usize::MAX); } #[derive(Debug)] |