1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4macro_rules! define_id {
5 ($(#[$doc:meta])* $name:ident) => {
6 $(#[$doc])*
7 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
8 #[serde(transparent)]
9 #[allow(missing_docs)]
10 pub struct $name(pub String);
11
12 impl $name {
13 pub fn new(s: impl Into<String>) -> Self {
15 Self(s.into())
16 }
17
18 pub fn as_str(&self) -> &str {
20 &self.0
21 }
22 }
23
24 impl fmt::Display for $name {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "{}", self.0)
27 }
28 }
29
30 impl From<&str> for $name {
31 fn from(s: &str) -> Self {
32 Self(s.to_string())
33 }
34 }
35
36 impl From<String> for $name {
37 fn from(s: String) -> Self {
38 Self(s)
39 }
40 }
41 };
42}
43
44define_id!(
45 NodeId
47);
48define_id!(
49 TypeId
51);
52define_id!(
53 FuncId
55);
56define_id!(
57 ModuleId
59);
60define_id!(
61 Symbol
63);