Skip to main content

docx_rs/documents/elements/
text_direction.rs

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