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