docx_rs/documents/elements/
sz_cs.rs1use crate::documents::BuildXML;
2use crate::xml_builder::*;
3use serde::{Deserialize, Serialize, Serializer};
4use std::io::Write;
5
6#[derive(Deserialize, Debug, Clone, PartialEq)]
7pub struct SzCs {
8 val: usize,
9}
10
11impl SzCs {
12 pub fn new(val: usize) -> SzCs {
13 SzCs { val }
14 }
15}
16
17impl BuildXML for SzCs {
18 fn build_to<W: Write>(
19 &self,
20 stream: xml::writer::EventWriter<W>,
21 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
22 XMLBuilder::from(stream).sz_cs(self.val)?.into_inner()
23 }
24}
25
26impl Serialize for SzCs {
27 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
28 where
29 S: Serializer,
30 {
31 serializer.serialize_u32(self.val as u32)
32 }
33}
34
35#[cfg(test)]
36mod tests {
37
38 use super::*;
39 #[cfg(test)]
40 use pretty_assertions::assert_eq;
41 use std::str;
42
43 #[test]
44 fn test_sz_cs() {
45 let c = SzCs::new(20);
46 let b = c.build();
47 assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:szCs w:val="20" />"#);
48 }
49}