diff --git a/docx-core/src/documents/elements/level.rs b/docx-core/src/documents/elements/level.rs index aa43456..414fbdf 100644 --- a/docx-core/src/documents/elements/level.rs +++ b/docx-core/src/documents/elements/level.rs @@ -9,7 +9,7 @@ pub struct Level<'a> { format: NumberFormat<'a>, text: LevelText<'a>, jc: LevelJc<'a>, - paragraph_property: ParagraphProperty<'a>, + paragraph_property: ParagraphProperty, } impl<'a> Level<'a> { diff --git a/docx-core/src/documents/elements/numbering.rs b/docx-core/src/documents/elements/numbering.rs index 29a5c11..afd4fd3 100644 --- a/docx-core/src/documents/elements/numbering.rs +++ b/docx-core/src/documents/elements/numbering.rs @@ -3,12 +3,12 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Numbering<'a> { - id: &'a str, + id: usize, levels: Vec>, } impl<'a> Numbering<'a> { - pub fn new(id: &'a str) -> Self { + pub fn new(id: usize) -> Self { Self { id, levels: vec![] } } @@ -20,16 +20,13 @@ impl<'a> Numbering<'a> { impl<'a> BuildXML for Numbering<'a> { fn build(&self) -> Vec { + let id = format!("{}", self.id); let mut b = XMLBuilder::new(); - b = b.open_abstract_num(self.id); + b = b.open_abstract_num(&id); for l in &self.levels { b = b.add_child(l); } - b.close() - .open_num(self.id) - .abstract_num_id(self.id) - .close() - .build() + b.close().open_num(&id).abstract_num_id(&id).close().build() } } @@ -44,7 +41,7 @@ mod tests { #[test] fn test_numbering() { - let mut c = Numbering::new("0"); + let mut c = Numbering::new(0); c = c.add_level(Level::new( 1, Start::new(1), diff --git a/docx-core/src/documents/elements/numbering_id.rs b/docx-core/src/documents/elements/numbering_id.rs index 933e289..af48517 100644 --- a/docx-core/src/documents/elements/numbering_id.rs +++ b/docx-core/src/documents/elements/numbering_id.rs @@ -2,17 +2,17 @@ use crate::documents::BuildXML; use crate::xml_builder::*; #[derive(Debug, Clone)] -pub struct NumberingId<'a> { - id: &'a str, +pub struct NumberingId { + id: usize, } -impl<'a> NumberingId<'a> { - pub fn new(id: &'a str) -> NumberingId<'a> { +impl NumberingId { + pub fn new(id: usize) -> NumberingId { NumberingId { id } } } -impl<'a> BuildXML for NumberingId<'a> { +impl BuildXML for NumberingId { fn build(&self) -> Vec { let b = XMLBuilder::new(); b.num_id(self.id).build() @@ -29,8 +29,8 @@ mod tests { #[test] fn test_num_id() { - let c = NumberingId::new("abc"); + let c = NumberingId::new(0); let b = c.build(); - assert_eq!(str::from_utf8(&b).unwrap(), r#""#); + assert_eq!(str::from_utf8(&b).unwrap(), r#""#); } } diff --git a/docx-core/src/documents/elements/numbering_property.rs b/docx-core/src/documents/elements/numbering_property.rs index 4856832..627a53e 100644 --- a/docx-core/src/documents/elements/numbering_property.rs +++ b/docx-core/src/documents/elements/numbering_property.rs @@ -3,18 +3,18 @@ use crate::documents::BuildXML; use crate::xml_builder::*; #[derive(Debug, Clone)] -pub struct NumberingProperty<'a> { - id: NumberingId<'a>, +pub struct NumberingProperty { + id: NumberingId, level: IndentLevel, } -impl<'a> NumberingProperty<'a> { - pub fn new(id: NumberingId<'a>, level: IndentLevel) -> NumberingProperty { +impl NumberingProperty { + pub fn new(id: NumberingId, level: IndentLevel) -> NumberingProperty { Self { id, level } } } -impl<'a> BuildXML for NumberingProperty<'a> { +impl BuildXML for NumberingProperty { fn build(&self) -> Vec { let b = XMLBuilder::new(); b.open_numbering_property() @@ -35,11 +35,11 @@ mod tests { #[test] fn test_num_property() { - let c = NumberingProperty::new(NumberingId::new("abc"), IndentLevel::new(3)); + let c = NumberingProperty::new(NumberingId::new(0), IndentLevel::new(3)); let b = c.build(); assert_eq!( str::from_utf8(&b).unwrap(), - r#""# + r#""# ); } } diff --git a/docx-core/src/documents/elements/paragraph.rs b/docx-core/src/documents/elements/paragraph.rs index 62122ae..5d59c1a 100644 --- a/docx-core/src/documents/elements/paragraph.rs +++ b/docx-core/src/documents/elements/paragraph.rs @@ -6,7 +6,7 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Paragraph<'a> { pub(crate) children: Vec>, - property: ParagraphProperty<'a>, + property: ParagraphProperty, attrs: Vec<(String, String)>, } @@ -119,7 +119,7 @@ impl<'a> Paragraph<'a> { self } - pub fn numbering(mut self, id: NumberingId<'a>, level: IndentLevel) -> Self { + pub fn numbering(mut self, id: NumberingId, level: IndentLevel) -> Self { self.property = self.property.numbering(id, level); self } @@ -205,11 +205,11 @@ mod tests { fn test_numbering() { let b = Paragraph::new() .add_run(Run::new().add_text("Hello")) - .numbering(NumberingId::new("abc"), IndentLevel::new(1)) + .numbering(NumberingId::new(0), IndentLevel::new(1)) .build(); assert_eq!( str::from_utf8(&b).unwrap(), - r#"Hello"# + r#"Hello"# ); } } diff --git a/docx-core/src/documents/elements/paragraph_property.rs b/docx-core/src/documents/elements/paragraph_property.rs index e42dec3..eb688f0 100644 --- a/docx-core/src/documents/elements/paragraph_property.rs +++ b/docx-core/src/documents/elements/paragraph_property.rs @@ -6,15 +6,15 @@ use crate::types::{AlignmentType, SpecialIndentType}; use crate::xml_builder::*; #[derive(Debug, Clone)] -pub struct ParagraphProperty<'a> { +pub struct ParagraphProperty { run_property: RunProperty, style: ParagraphStyle, - numbering_property: Option>, + numbering_property: Option, alignment: Option, indent: Option, } -impl<'a> Default for ParagraphProperty<'a> { +impl Default for ParagraphProperty { fn default() -> Self { let s: Option<&str> = None; ParagraphProperty { @@ -32,8 +32,8 @@ impl<'a> Default for ParagraphProperty<'a> { // This element specifies a set of paragraph properties which shall be applied to the contents of the parent // paragraph after all style/numbering/table properties have been applied to the text. These properties are defined // as direct formatting, since they are directly applied to the paragraph and supersede any formatting from styles. -impl<'a> ParagraphProperty<'a> { - pub fn new() -> ParagraphProperty<'a> { +impl ParagraphProperty { + pub fn new() -> ParagraphProperty { Default::default() } @@ -52,13 +52,13 @@ impl<'a> ParagraphProperty<'a> { self } - pub fn numbering(mut self, id: NumberingId<'a>, level: IndentLevel) -> Self { + pub fn numbering(mut self, id: NumberingId, level: IndentLevel) -> Self { self.numbering_property = Some(NumberingProperty::new(id, level)); self } } -impl<'a> BuildXML for ParagraphProperty<'a> { +impl BuildXML for ParagraphProperty { fn build(&self) -> Vec { XMLBuilder::new() .open_paragraph_property() diff --git a/docx-core/src/documents/elements/style.rs b/docx-core/src/documents/elements/style.rs index 7fef5b8..313d29d 100644 --- a/docx-core/src/documents/elements/style.rs +++ b/docx-core/src/documents/elements/style.rs @@ -5,15 +5,15 @@ use crate::StyleType; use super::{BasedOn, Name, Next, ParagraphProperty, QFormat, RunProperty}; #[derive(Debug)] -pub struct Style<'a> { +pub struct Style { style_id: String, name: Name, style_type: StyleType, run_property: RunProperty, - paragraph_property: ParagraphProperty<'a>, + paragraph_property: ParagraphProperty, } -impl<'a> Default for Style<'a> { +impl Default for Style { fn default() -> Self { let name = Name::new(""); let rpr = RunProperty::new(); @@ -28,7 +28,7 @@ impl<'a> Default for Style<'a> { } } -impl<'a> Style<'a> { +impl Style { pub fn new( style_id: impl Into, name: impl Into, @@ -65,7 +65,7 @@ impl<'a> Style<'a> { } } -impl<'a> BuildXML for Style<'a> { +impl BuildXML for Style { fn build(&self) -> Vec { let b = XMLBuilder::new(); // Set "Normal" as default if you need change these values please fix it diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index c1b61b9..975d32c 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -35,7 +35,7 @@ pub struct Docx<'a> { rels: Rels, document_rels: DocumentRels, doc_props: DocProps<'a>, - styles: Styles<'a>, + styles: Styles, document: Document<'a>, comments: Comments<'a>, numberings: Numberings<'a>, diff --git a/docx-core/src/documents/numberings.rs b/docx-core/src/documents/numberings.rs index 2f7e5d0..3afd65d 100644 --- a/docx-core/src/documents/numberings.rs +++ b/docx-core/src/documents/numberings.rs @@ -37,7 +37,7 @@ impl<'a> BuildXML for Numberings<'a> { } fn create_default_numbering() -> Numbering<'static> { - Numbering::new("0") + Numbering::new(0) .add_level( Level::new( 0, diff --git a/docx-core/src/documents/styles.rs b/docx-core/src/documents/styles.rs index 79607b3..66edbdc 100644 --- a/docx-core/src/documents/styles.rs +++ b/docx-core/src/documents/styles.rs @@ -4,23 +4,23 @@ use crate::types::*; use crate::xml_builder::*; #[derive(Debug)] -pub struct Styles<'a> { +pub struct Styles { doc_defaults: DocDefaults, - styles: Vec>, + styles: Vec