From 37d4a157d51fada524b193119670ea1dec80be58 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Mon, 11 Nov 2019 10:41:59 +0900 Subject: [PATCH] feat: add pack method --- docx-core/src/documents/xml_docx.rs | 14 +++++++++++++- docx-core/src/lib.rs | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docx-core/src/documents/xml_docx.rs b/docx-core/src/documents/xml_docx.rs index 11d94c5..2c07793 100644 --- a/docx-core/src/documents/xml_docx.rs +++ b/docx-core/src/documents/xml_docx.rs @@ -1,5 +1,8 @@ use super::XMLDocProps; -use wasm_bindgen::prelude::*; + +use crate::zipper; +use std::io::prelude::*; +use std::io::Seek; #[derive(Debug)] pub struct XMLDocx { @@ -9,3 +12,12 @@ pub struct XMLDocx { pub styles: Vec, pub document: Vec, } + +impl XMLDocx { + pub fn pack(self, w: W) -> zip::result::ZipResult<()> + where + W: Write + Seek, + { + zipper::zip(w, self) + } +} diff --git a/docx-core/src/lib.rs b/docx-core/src/lib.rs index b438a56..741acd8 100644 --- a/docx-core/src/lib.rs +++ b/docx-core/src/lib.rs @@ -8,10 +8,10 @@ pub use types::*; pub use zipper::*; pub fn simple() { - let xml = Docx::new() - .add_paragraph(Paragraph::new().add_run(Run::new("Hello"))) - .build(); let path = std::path::Path::new("./test.docx"); let file = std::fs::File::create(&path).unwrap(); - zip(file, xml); + Docx::new() + .add_paragraph(Paragraph::new().add_run(Run::new("Hello"))) + .build() + .pack(file); }