docx_rust/formatting/
justification.rs

1use hard_xml::{XmlRead, XmlWrite};
2
3use crate::{__string_enum, __xml_test_suites};
4
5/// Justification
6///
7/// ```rust
8/// use docx_rust::formatting::*;
9///
10/// let jc = Justification::from(JustificationVal::Start);
11/// ```
12#[derive(Debug, XmlRead, XmlWrite, Clone)]
13#[cfg_attr(test, derive(PartialEq))]
14#[xml(tag = "w:jc")]
15pub struct Justification {
16    #[xml(attr = "w:val")]
17    pub value: JustificationVal,
18}
19
20impl From<JustificationVal> for Justification {
21    fn from(value: JustificationVal) -> Self {
22        Justification { value }
23    }
24}
25
26#[derive(Debug, Clone)]
27#[cfg_attr(test, derive(PartialEq))]
28pub enum JustificationVal {
29    Start,
30    End,
31    Center,
32    Both,
33    Distribute,
34    Right,
35    Left,
36}
37
38__string_enum! {
39    JustificationVal {
40        Start = "start",
41        End = "end",
42        Center = "center",
43        Both = "both",
44        Distribute = "distribute",
45        Right = "right",
46        Left = "left",
47    }
48}
49
50__xml_test_suites!(
51    Justification,
52    Justification::from(JustificationVal::Start),
53    r#"<w:jc w:val="start"/>"#,
54);