docx_rust/formatting/
numbering_property.rs1#![allow(unused_must_use)]
2use std::borrow::Cow;
3
4use hard_xml::{XmlRead, XmlWrite};
5
6use crate::__xml_test_suites;
7use crate::formatting::{IndentLevel, NumberingId};
8
9#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
17#[cfg_attr(test, derive(PartialEq))]
18#[xml(tag = "w:numPr")]
19pub struct NumberingProperty<'a> {
20 #[xml(child = "w:ilvl")]
22 pub level: Option<IndentLevel>,
23 #[xml(child = "w:numId")]
25 pub id: Option<NumberingId>,
26 #[xml(child = "w:numberingChange")]
28 pub numbering_change: Option<NumberingChange<'a>>,
29 #[xml(child = "w:ins")]
31 pub ins: Option<InsertedProperties<'a>>,
32}
33
34#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
35#[cfg_attr(test, derive(PartialEq))]
36#[xml(tag = "w:ins")]
37pub struct InsertedProperties<'a> {
38 #[xml(attr = "w:id")]
39 pub id: Option<isize>,
40 #[xml(attr = "w:author")]
41 pub author: Option<Cow<'a, str>>,
42 #[xml(attr = "w:date")]
43 pub date: Option<Cow<'a, str>>,
44}
45
46#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
47#[cfg_attr(test, derive(PartialEq))]
48#[xml(tag = "w:numberingChange")]
49pub struct NumberingChange<'a> {
50 #[xml(attr = "w:id")]
51 pub id: Option<isize>,
52 #[xml(attr = "w:author")]
53 pub author: Option<Cow<'a, str>>,
54 #[xml(attr = "w:date")]
55 pub date: Option<Cow<'a, str>>,
56 #[xml(attr = "w:original")]
57 pub original: Option<Cow<'a, str>>,
58}
59
60impl From<(isize, isize)> for NumberingProperty<'_> {
61 fn from(val: (isize, isize)) -> Self {
62 NumberingProperty {
63 id: Some(NumberingId { value: val.0 }),
64 level: Some(IndentLevel { value: val.1 }),
65 numbering_change: None,
66 ins: None,
67 }
68 }
69}
70
71__xml_test_suites!(
72 NumberingProperty,
73 NumberingProperty::default(),
74 r#"<w:numPr/>"#,
75 NumberingProperty::from((20, 40)),
76 r#"<w:numPr><w:ilvl w:val="40"/><w:numId w:val="20"/></w:numPr>"#,
77);