docx_rs/documents/elements/
bookmark_end.rs1use serde::Serialize;
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::xml_builder::*;
6
7#[derive(Serialize, Debug, Clone, PartialEq)]
8pub struct BookmarkEnd {
9 pub id: usize,
10}
11
12impl BookmarkEnd {
13 pub fn new(id: usize) -> BookmarkEnd {
14 BookmarkEnd { id }
15 }
16}
17
18impl BuildXML for BookmarkEnd {
19 fn build_to<W: Write>(
20 &self,
21 stream: xml::writer::EventWriter<W>,
22 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
23 XMLBuilder::from(stream)
24 .bookmark_end(&self.id.to_string())?
25 .into_inner()
26 }
27}
28
29#[cfg(test)]
30mod tests {
31
32 use super::*;
33 #[cfg(test)]
34 use pretty_assertions::assert_eq;
35 use std::str;
36
37 #[test]
38 fn test_bookmark_end() {
39 let c = BookmarkEnd::new(0);
40 let b = c.build();
41 assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:bookmarkEnd w:id="0" />"#);
42 }
43}