html_site_generator/html/
address.rs1use std::io::Write;
2
3use anyhow::Result;
4
5use crate::html::IntoHtmlNode;
6
7#[derive(Debug)]
8pub struct Address {
9 elements: Vec<Box<dyn IntoHtmlNode>>,
10}
11
12impl Address {
13 pub fn new() -> Self {
14 Address {
15 elements: Vec::new(),
16 }
17 }
18
19 pub fn add_element(&mut self, item: impl IntoHtmlNode + 'static) {
20 self.elements.push(Box::new(item))
21 }
22}
23
24impl IntoHtmlNode for Address {
25 fn transform_into_html_node(&self, buffer: &mut dyn Write) -> Result<()> {
26 writeln!(buffer, "<address>")?;
27
28 for element in &self.elements {
29 element.transform_into_html_node(buffer)?;
30 }
31
32 writeln!(buffer, "</address>")?;
33
34 Ok(())
35 }
36}