diff --git a/src/main.rs b/src/main.rs index f56f839..54521e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,9 +43,21 @@ struct Comment { text: Box, } +struct SiteInfo { + comments: Vec, +} + +impl SiteInfo { + fn new() -> Self { + Self { + comments: Vec::new(), + } + } +} + #[derive(Default)] struct Context { - comments: HashMap, Vec>, + infos: HashMap, SiteInfo>, } impl Context { @@ -126,9 +138,9 @@ impl Context { }; use Entry::*; - let local_comments = match self.comments.entry(relative_path.clone().into_boxed_str()) { + let info = match self.infos.entry(relative_path.clone().into_boxed_str()) { Occupied(o) => o.into_mut(), - Vacant(v) => v.insert(Vec::new()), + Vacant(v) => v.insert(SiteInfo::new()), }; let mut entries = request.body.split('&'); @@ -159,7 +171,7 @@ impl Context { .unwrap_or_default() .into(); - local_comments.push(Comment { name, text }); + info.comments.push(Comment { name, text }); } } @@ -252,7 +264,7 @@ impl Context { }; let _ = stream.write_all(html.into_string().as_bytes()); - for Comment { name, text } in local_comments { + for Comment { name, text } in &info.comments { let _ = writeln!(stream, "
{name}{text}
"); }