This commit is contained in:
2026-03-24 13:40:27 +00:00
parent 4cee158206
commit e6cfef9a77
4 changed files with 237 additions and 31 deletions
+5 -1
View File
@@ -3,7 +3,7 @@ use std::collections::HashMap;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
pub struct NameId(pub u32);
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct NameInterner {
names: Vec<String>,
ids: HashMap<String, NameId>,
@@ -28,6 +28,10 @@ impl NameInterner {
id
}
pub fn get(&self, s: &str) -> Option<NameId> {
self.ids.get(s).copied()
}
pub fn resolve(&self, id: NameId) -> &str {
&self.names[id.0 as usize]
}