docx_rust/document/
field_char.rs

1use hard_xml::{XmlRead, XmlWrite};
2
3use crate::{__string_enum, __xml_test_suites};
4
5/// Break
6///
7/// ```rust
8/// use docx_rust::document::*;
9///
10/// let br = Break::from(BreakType::Page);
11/// ```
12#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
13#[cfg_attr(test, derive(PartialEq))]
14#[xml(tag = "w:fldChar")]
15pub struct FieldChar {
16    /// Specifies the break type of this break.
17    #[xml(attr = "w:fldCharType")]
18    pub ty: Option<CharType>,
19}
20
21impl<T: Into<Option<CharType>>> From<T> for FieldChar {
22    fn from(val: T) -> Self {
23        FieldChar { ty: val.into() }
24    }
25}
26
27/// Specifies the break type of a break
28///
29/// The default value is TextWrapping.
30#[derive(Debug, Clone)]
31#[cfg_attr(test, derive(PartialEq))]
32pub enum CharType {
33    /// Text restarts on the next column.
34    Begin,
35    /// Text restarts on the next page.
36    Separate,
37    /// Text restarts on the next line.
38    End,
39}
40
41__string_enum! {
42    CharType {
43        Begin = "begin",
44        Separate = "separate",
45        End = "end",
46    }
47}
48
49__xml_test_suites!(
50    FieldChar,
51    FieldChar::from(CharType::Begin),
52    r#"<w:fldChar w:fldCharType="begin"/>"#,
53);