docx_rs/documents/elements/
br.rs

1use serde::ser::{Serialize, SerializeStruct, Serializer};
2use serde::Deserialize;
3use std::io::Write;
4
5use crate::documents::BuildXML;
6use crate::types::*;
7use crate::xml_builder::*;
8
9#[derive(Debug, Clone, Deserialize, PartialEq)]
10pub struct Break {
11    break_type: BreakType,
12}
13
14impl Break {
15    pub fn new(t: BreakType) -> Break {
16        Break { break_type: t }
17    }
18}
19
20impl BuildXML for Break {
21    fn build_to<W: Write>(
22        &self,
23        stream: xml::writer::EventWriter<W>,
24    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
25        XMLBuilder::from(stream)
26            .br(&self.break_type.to_string())?
27            .into_inner()
28    }
29}
30
31impl Serialize for Break {
32    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
33    where
34        S: Serializer,
35    {
36        let mut t = serializer.serialize_struct("Break", 1)?;
37        t.serialize_field("breakType", &format!("{}", &self.break_type))?;
38        t.end()
39    }
40}