use super::Comment; use crate::documents::BuildXML; use crate::xml_builder::*; use serde::Serialize; #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct Comments { comments: Vec, } impl Comments { pub fn new() -> Self { Default::default() } pub(crate) fn add_comments(&mut self, comments: Vec) { self.comments = comments; } } impl Default for Comments { fn default() -> Self { Self { comments: vec![] } } } impl BuildXML for Comments { fn build(&self) -> Vec { let mut b = XMLBuilder::new().declaration(Some(true)).open_comments(); for c in &self.comments { b = b.add_child(c) } b.close().build() } } #[cfg(test)] mod tests { use super::*; #[cfg(test)] use pretty_assertions::assert_eq; use std::str; #[test] fn test_comments() { let b = Comments::new().build(); assert_eq!( str::from_utf8(&b).unwrap(), r#" "# ); } }