docx_rs/documents/elements/
default_tab_stop.rs1use crate::documents::BuildXML;
2use crate::xml_builder::*;
3use std::io::Write;
4
5use serde::{Serialize, Serializer};
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct DefaultTabStop {
9 val: usize,
10}
11
12impl DefaultTabStop {
13 pub fn new(val: usize) -> DefaultTabStop {
14 DefaultTabStop { val }
15 }
16}
17
18impl BuildXML for DefaultTabStop {
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 .default_tab_stop(self.val)?
25 .into_inner()
26 }
27}
28
29impl Serialize for DefaultTabStop {
30 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
31 where
32 S: Serializer,
33 {
34 serializer.serialize_u64(self.val as u64)
35 }
36}
37
38#[cfg(test)]
39mod tests {
40
41 use super::*;
42 #[cfg(test)]
43 use pretty_assertions::assert_eq;
44 use std::str;
45
46 #[test]
47 fn test_zoom() {
48 let c = DefaultTabStop::new(20);
49 let b = c.build();
50 assert_eq!(
51 str::from_utf8(&b).unwrap(),
52 r#"<w:defaultTabStop w:val="20" />"#
53 );
54 }
55}