docx_rs/documents/elements/
comment_range_start.rs1use serde::Serialize;
2use std::io::Write;
3
4use super::Comment;
5use crate::documents::BuildXML;
6use crate::xml_builder::*;
7
8#[derive(Serialize, Debug, Clone, PartialEq)]
9pub struct CommentRangeStart {
10 pub id: usize,
11 pub comment: Comment,
12}
13
14impl CommentRangeStart {
15 pub fn new(comment: Comment) -> CommentRangeStart {
16 CommentRangeStart {
17 id: comment.id(),
18 comment,
19 }
20 }
21
22 pub(crate) fn comment(&mut self, comment: Comment) {
23 self.comment = comment;
24 }
25
26 pub(crate) fn get_comment(&self) -> Comment {
27 self.comment.clone()
28 }
29
30 pub(crate) fn get_id(&self) -> usize {
31 self.id
32 }
33}
34
35impl BuildXML for CommentRangeStart {
36 fn build_to<W: Write>(
37 &self,
38 stream: xml::writer::EventWriter<W>,
39 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
40 XMLBuilder::from(stream)
41 .comment_range_start(&self.id.to_string())?
42 .into_inner()
43 }
44}
45
46#[cfg(test)]
47mod tests {
48
49 use super::*;
50 #[cfg(test)]
51 use pretty_assertions::assert_eq;
52 use std::str;
53
54 #[test]
55 fn test_comment_range_start() {
56 let c = CommentRangeStart::new(Comment::new(1));
57 let b = c.build();
58 assert_eq!(
59 str::from_utf8(&b).unwrap(),
60 r#"<w:commentRangeStart w:id="1" />"#
61 );
62 }
63}