natter/src/intermediate/registry.rs
2023-10-27 15:05:50 -04:00

25 lines
581 B
Rust

use std::collections::HashMap;
type IdCounter = u16;
pub(crate) struct Registry<'parse> {
id_counter: IdCounter,
targets: HashMap<&'parse str, String>,
}
impl<'parse> Registry<'parse> {
pub(crate) fn new() -> Registry<'parse> {
Registry {
id_counter: 0,
targets: HashMap::new(),
}
}
pub(crate) fn get_target<'b>(&'b mut self, body: &'parse str) -> &'b String {
self.targets.entry(body).or_insert_with(|| {
self.id_counter += 1;
format!("target_{}", self.id_counter)
})
}
}