Add target.

This commit is contained in:
Tom Alexander
2023-10-27 14:54:54 -04:00
parent c6cf5f75ac
commit 7b01230234
9 changed files with 80 additions and 15 deletions

View File

@@ -2,20 +2,20 @@ use std::collections::HashMap;
type IdCounter = u16;
pub(crate) struct Registry<'p> {
pub(crate) struct Registry<'parse> {
id_counter: IdCounter,
targets: HashMap<&'p str, String>,
targets: HashMap<&'parse str, String>,
}
impl<'p> Registry<'p> {
pub(crate) fn new() -> Registry<'p> {
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: &'p str) -> &'b String {
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)