docx_rs/documents/elements/
start.rs

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