docx_rust/document/
break.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:br")]
15pub struct Break {
16    /// Specifies the break type of this break.
17    #[xml(attr = "w:type")]
18    pub ty: Option<BreakType>,
19}
20
21impl<T: Into<Option<BreakType>>> From<T> for Break {
22    fn from(val: T) -> Self {
23        Break { 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 BreakType {
33    /// Text restarts on the next column.
34    Column,
35    /// Text restarts on the next page.
36    Page,
37    /// Text restarts on the next line.
38    TextWrapping,
39}
40
41#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
42#[cfg_attr(test, derive(PartialEq))]
43#[xml(tag = "w:lastRenderedPageBreak")]
44pub struct LastRenderedPageBreak {}
45
46__string_enum! {
47    BreakType {
48        Column = "column",
49        Page = "page",
50        TextWrapping = "textWrapping",
51    }
52}
53
54__xml_test_suites!(
55    Break,
56    Break::default(),
57    r#"<w:br/>"#,
58    Break::from(BreakType::Page),
59    r#"<w:br w:type="page"/>"#,
60);