pedant_types/resolution/
id.rs1use std::marker::PhantomData;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[repr(transparent)]
10#[serde(transparent)]
11pub struct Id<K> {
12 index: u32,
13 #[serde(skip)]
14 kind: PhantomData<fn() -> K>,
15}
16
17impl<K> Id<K> {
18 pub fn index(self) -> u32 {
20 self.index
21 }
22
23 pub(crate) fn new(index: u32) -> Self {
24 Self {
25 index,
26 kind: PhantomData,
27 }
28 }
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub struct UnitIdKind;
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
37pub struct DefinitionIdKind;
38
39#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
41pub struct ReferenceIdKind;
42
43pub type ResolutionUnitId = Id<UnitIdKind>;
45
46pub type DefinitionId = Id<DefinitionIdKind>;
48
49pub type ReferenceId = Id<ReferenceIdKind>;