diff --git a/docx-core/src/documents/comments.rs b/docx-core/src/documents/comments.rs index 282e2bf..b946957 100644 --- a/docx-core/src/documents/comments.rs +++ b/docx-core/src/documents/comments.rs @@ -4,7 +4,7 @@ use crate::xml_builder::*; use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct Comments { pub(crate) comments: Vec, @@ -28,12 +28,6 @@ impl Comments { } } -impl Default for Comments { - fn default() -> Self { - Self { comments: vec![] } - } -} - impl BuildXML for Comments { fn build(&self) -> Vec { let mut b = XMLBuilder::new().declaration(Some(true)).open_comments(); diff --git a/docx-core/src/documents/comments_extended.rs b/docx-core/src/documents/comments_extended.rs index a032885..369af00 100644 --- a/docx-core/src/documents/comments_extended.rs +++ b/docx-core/src/documents/comments_extended.rs @@ -5,7 +5,7 @@ use crate::documents::BuildXML; use crate::xml_builder::*; // i.e. -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct CommentsExtended { pub children: Vec, @@ -21,12 +21,6 @@ impl CommentsExtended { } } -impl Default for CommentsExtended { - fn default() -> Self { - Self { children: vec![] } - } -} - impl BuildXML for CommentsExtended { fn build(&self) -> Vec { let mut b = XMLBuilder::new(); diff --git a/docx-core/src/documents/doc_props/app.rs b/docx-core/src/documents/doc_props/app.rs index e3dfcbf..c46eae9 100644 --- a/docx-core/src/documents/doc_props/app.rs +++ b/docx-core/src/documents/doc_props/app.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct AppProps {} @@ -13,12 +13,6 @@ impl AppProps { } } -impl Default for AppProps { - fn default() -> Self { - Self {} - } -} - impl BuildXML for AppProps { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/doc_props/core.rs b/docx-core/src/documents/doc_props/core.rs index d2e662b..fbce26f 100644 --- a/docx-core/src/documents/doc_props/core.rs +++ b/docx-core/src/documents/doc_props/core.rs @@ -3,13 +3,13 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct CoreProps { config: CorePropsConfig, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct CorePropsConfig { created: Option, @@ -23,30 +23,6 @@ pub struct CorePropsConfig { title: Option, } -impl Default for CorePropsConfig { - fn default() -> Self { - Self { - created: None, - creator: None, - description: None, - language: None, - last_modified_by: None, - modified: None, - revision: None, - subject: None, - title: None, - } - } -} - -impl Default for CoreProps { - fn default() -> Self { - Self { - config: CorePropsConfig::default(), - } - } -} - impl CoreProps { pub(crate) fn new(config: CorePropsConfig) -> CoreProps { CoreProps { config } diff --git a/docx-core/src/documents/elements/instr_text.rs b/docx-core/src/documents/elements/instr_text.rs index e3db9f2..f690ee9 100644 --- a/docx-core/src/documents/elements/instr_text.rs +++ b/docx-core/src/documents/elements/instr_text.rs @@ -96,6 +96,7 @@ mod tests { #[test] fn test_toc_instr() { + #[allow(unused_allocation)] let b = Box::new(InstrText::TOC(InstrToC::new().heading_styles_range(1, 3))).build(); assert_eq!( str::from_utf8(&b).unwrap(), @@ -105,6 +106,7 @@ mod tests { #[test] fn test_pageref_instr() { + #[allow(unused_allocation)] let b = Box::new(InstrText::PAGEREF( InstrPAGEREF::new("_Toc90425847").hyperlink(), )) diff --git a/docx-core/src/documents/elements/instr_toc.rs b/docx-core/src/documents/elements/instr_toc.rs index c0beb11..6ae8c1f 100644 --- a/docx-core/src/documents/elements/instr_toc.rs +++ b/docx-core/src/documents/elements/instr_toc.rs @@ -255,7 +255,7 @@ impl BuildXML for InstrToC { fn parse_level_range(i: &str) -> Option<(usize, usize)> { let r = i.replace(""", "").replace('\"', ""); let r: Vec<&str> = r.split('-').collect(); - if let Some(s) = r.get(0) { + if let Some(s) = r.first() { if let Ok(s) = usize::from_str(s) { if let Some(e) = r.get(1) { if let Ok(e) = usize::from_str(e) { diff --git a/docx-core/src/documents/elements/is_lgl.rs b/docx-core/src/documents/elements/is_lgl.rs index 822a3d5..efdd9cc 100644 --- a/docx-core/src/documents/elements/is_lgl.rs +++ b/docx-core/src/documents/elements/is_lgl.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize, Serializer}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Deserialize, PartialEq)] +#[derive(Debug, Clone, Deserialize, PartialEq, Default)] pub struct IsLgl {} impl IsLgl { @@ -12,12 +12,6 @@ impl IsLgl { } } -impl Default for IsLgl { - fn default() -> Self { - IsLgl {} - } -} - impl BuildXML for IsLgl { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/line_spacing.rs b/docx-core/src/documents/elements/line_spacing.rs index 6007f3e..e95e2ac 100644 --- a/docx-core/src/documents/elements/line_spacing.rs +++ b/docx-core/src/documents/elements/line_spacing.rs @@ -52,7 +52,7 @@ impl LineSpacing { } pub fn line(mut self, line: i32) -> Self { - self.line = Some(line as i32); + self.line = Some(line); self } } diff --git a/docx-core/src/documents/elements/mc_fallback.rs b/docx-core/src/documents/elements/mc_fallback.rs index 94c57c0..76700b4 100644 --- a/docx-core/src/documents/elements/mc_fallback.rs +++ b/docx-core/src/documents/elements/mc_fallback.rs @@ -1,10 +1,7 @@ -// use super::*; +use crate::documents::BuildXML; use serde::Serialize; -use crate::documents::BuildXML; -// use crate::xml_builder::*; - -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] pub struct McFallback {} impl McFallback { @@ -13,12 +10,6 @@ impl McFallback { } } -impl Default for McFallback { - fn default() -> Self { - McFallback {} - } -} - impl BuildXML for McFallback { fn build(&self) -> Vec { // Ignore for now diff --git a/docx-core/src/documents/elements/mod.rs b/docx-core/src/documents/elements/mod.rs index d2314fa..808ded4 100644 --- a/docx-core/src/documents/elements/mod.rs +++ b/docx-core/src/documents/elements/mod.rs @@ -207,7 +207,6 @@ pub use numbering::*; pub use numbering_id::*; pub use numbering_property::*; pub use outline_lvl::*; -pub use page_margin::*; pub use page_num::*; pub use page_num_type::*; pub use page_size::*; diff --git a/docx-core/src/documents/elements/numbering_property.rs b/docx-core/src/documents/elements/numbering_property.rs index f1d19cf..b765ddb 100644 --- a/docx-core/src/documents/elements/numbering_property.rs +++ b/docx-core/src/documents/elements/numbering_property.rs @@ -5,21 +5,12 @@ use super::{IndentLevel, NumberingId}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Default)] pub struct NumberingProperty { pub id: Option, pub level: Option, } -impl Default for NumberingProperty { - fn default() -> Self { - NumberingProperty { - id: None, - level: None, - } - } -} - impl NumberingProperty { pub fn new() -> NumberingProperty { Default::default() diff --git a/docx-core/src/documents/elements/q_format.rs b/docx-core/src/documents/elements/q_format.rs index 7990dfc..de55368 100644 --- a/docx-core/src/documents/elements/q_format.rs +++ b/docx-core/src/documents/elements/q_format.rs @@ -7,6 +7,7 @@ use crate::xml_builder::*; // application. If this element is set, then this style has been designated as being particularly important for the // current document, and this information can be used by an application in any means desired. [Note: This setting // 637ECMA-376 Part 1 does not imply any behavior for the style, only that the style is of particular significance for this document. end note] +#[derive(Default)] pub struct QFormat {} impl QFormat { @@ -15,11 +16,6 @@ impl QFormat { } } -impl Default for QFormat { - fn default() -> Self { - Self {} - } -} impl BuildXML for QFormat { fn build(&self) -> Vec { diff --git a/docx-core/src/documents/elements/spec_vanish.rs b/docx-core/src/documents/elements/spec_vanish.rs index b262eb8..da45187 100644 --- a/docx-core/src/documents/elements/spec_vanish.rs +++ b/docx-core/src/documents/elements/spec_vanish.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize, Serializer}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Deserialize, PartialEq)] +#[derive(Debug, Clone, Deserialize, PartialEq, Default)] pub struct SpecVanish {} impl SpecVanish { @@ -12,12 +12,6 @@ impl SpecVanish { } } -impl Default for SpecVanish { - fn default() -> Self { - SpecVanish {} - } -} - impl BuildXML for SpecVanish { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/start.rs b/docx-core/src/documents/elements/start.rs index abd4099..434153b 100644 --- a/docx-core/src/documents/elements/start.rs +++ b/docx-core/src/documents/elements/start.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Serializer}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Default)] pub struct Start { val: usize, } @@ -14,12 +14,6 @@ impl Start { } } -impl Default for Start { - fn default() -> Self { - Start { val: 0 } - } -} - impl BuildXML for Start { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/text_box_content.rs b/docx-core/src/documents/elements/text_box_content.rs index 002123a..5689507 100644 --- a/docx-core/src/documents/elements/text_box_content.rs +++ b/docx-core/src/documents/elements/text_box_content.rs @@ -5,7 +5,7 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] pub struct TextBoxContent { pub children: Vec, pub has_numbering: bool, @@ -62,15 +62,6 @@ impl TextBoxContent { } } -impl Default for TextBoxContent { - fn default() -> Self { - TextBoxContent { - children: vec![], - has_numbering: false, - } - } -} - impl BuildXML for TextBoxContent { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/vanish.rs b/docx-core/src/documents/elements/vanish.rs index 5103425..eee3eac 100644 --- a/docx-core/src/documents/elements/vanish.rs +++ b/docx-core/src/documents/elements/vanish.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize, Serializer}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Deserialize, PartialEq)] +#[derive(Debug, Clone, Deserialize, PartialEq, Default)] pub struct Vanish {} impl Vanish { @@ -12,12 +12,6 @@ impl Vanish { } } -impl Default for Vanish { - fn default() -> Self { - Vanish {} - } -} - impl BuildXML for Vanish { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/wp_anchor.rs b/docx-core/src/documents/elements/wp_anchor.rs index cd01587..650152a 100644 --- a/docx-core/src/documents/elements/wp_anchor.rs +++ b/docx-core/src/documents/elements/wp_anchor.rs @@ -4,7 +4,7 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct WpAnchor { pub children: Vec, @@ -32,12 +32,6 @@ impl WpAnchor { } } -impl Default for WpAnchor { - fn default() -> Self { - WpAnchor { children: vec![] } - } -} - impl BuildXML for WpAnchor { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/wps_shape.rs b/docx-core/src/documents/elements/wps_shape.rs index d5b55c7..ab2a0ea 100644 --- a/docx-core/src/documents/elements/wps_shape.rs +++ b/docx-core/src/documents/elements/wps_shape.rs @@ -5,7 +5,7 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct WpsShape { children: Vec, @@ -43,12 +43,6 @@ impl WpsShape { } } -impl Default for WpsShape { - fn default() -> Self { - WpsShape { children: vec![] } - } -} - impl BuildXML for WpsShape { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/wps_text_box.rs b/docx-core/src/documents/elements/wps_text_box.rs index 5431b4d..0a5178b 100644 --- a/docx-core/src/documents/elements/wps_text_box.rs +++ b/docx-core/src/documents/elements/wps_text_box.rs @@ -4,7 +4,7 @@ use serde::Serialize; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct WpsTextBox { pub children: Vec, @@ -25,15 +25,6 @@ impl WpsTextBox { } } -impl Default for WpsTextBox { - fn default() -> Self { - WpsTextBox { - children: vec![], - has_numbering: false, - } - } -} - impl BuildXML for WpsTextBox { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/font_table.rs b/docx-core/src/documents/font_table.rs index e9d2a01..dd06237 100644 --- a/docx-core/src/documents/font_table.rs +++ b/docx-core/src/documents/font_table.rs @@ -5,7 +5,7 @@ use crate::xml_builder::*; use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct FontTable {} @@ -15,12 +15,6 @@ impl FontTable { } } -impl Default for FontTable { - fn default() -> Self { - Self {} - } -} - impl BuildXML for FontTable { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index 5d86bba..b8d505a 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -96,7 +96,7 @@ impl ser::Serialize for Image { where S: ser::Serializer, { - let base64 = base64::display::Base64Display::with_config(&*self.0, base64::STANDARD); + let base64 = base64::display::Base64Display::with_config(&self.0, base64::STANDARD); serializer.collect_str(&base64) } } @@ -106,7 +106,7 @@ impl ser::Serialize for Png { where S: ser::Serializer, { - let base64 = base64::display::Base64Display::with_config(&*self.0, base64::STANDARD); + let base64 = base64::display::Base64Display::with_config(&self.0, base64::STANDARD); serializer.collect_str(&base64) } } @@ -259,7 +259,7 @@ impl Docx { // without 'image' crate we can only test for PNG file signature if buf.starts_with(&[137, 80, 78, 71, 13, 10, 26, 10]) { self.images - .push((id.into(), path.into(), Image(buf.clone()), Png(buf))); + .push((id.into(), path.into(), Image(buf.clone()), Png(buf))); } self } diff --git a/docx-core/src/documents/numberings.rs b/docx-core/src/documents/numberings.rs index 50f77af..40e1fd7 100644 --- a/docx-core/src/documents/numberings.rs +++ b/docx-core/src/documents/numberings.rs @@ -5,7 +5,7 @@ use crate::xml_builder::*; use serde::Serialize; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct Numberings { pub abstract_nums: Vec, @@ -28,15 +28,6 @@ impl Numberings { } } -impl Default for Numberings { - fn default() -> Self { - Self { - abstract_nums: vec![], - numberings: vec![], - } - } -} - impl BuildXML for Numberings { fn build(&self) -> Vec { let mut b = XMLBuilder::new().declaration(Some(true)).open_numbering(); diff --git a/docx-core/src/documents/rels.rs b/docx-core/src/documents/rels.rs index 32a0a21..caa37f6 100644 --- a/docx-core/src/documents/rels.rs +++ b/docx-core/src/documents/rels.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)] pub struct Rels { pub rels: Vec<(String, String, String)>, } @@ -61,12 +61,6 @@ impl Rels { } } -impl Default for Rels { - fn default() -> Self { - Rels { rels: Vec::new() } - } -} - impl BuildXML for Rels { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/taskpanes.rs b/docx-core/src/documents/taskpanes.rs index 6d448e4..1975a44 100644 --- a/docx-core/src/documents/taskpanes.rs +++ b/docx-core/src/documents/taskpanes.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy, Default)] pub struct Taskpanes {} impl Taskpanes { @@ -12,12 +12,6 @@ impl Taskpanes { } } -impl Default for Taskpanes { - fn default() -> Self { - Self {} - } -} - impl BuildXML for Taskpanes { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/taskpanes_rels.rs b/docx-core/src/documents/taskpanes_rels.rs index cb7d02c..b87959e 100644 --- a/docx-core/src/documents/taskpanes_rels.rs +++ b/docx-core/src/documents/taskpanes_rels.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::documents::BuildXML; use crate::xml_builder::*; -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)] pub struct TaskpanesRels { pub rels: Vec<(String, String, String)>, } @@ -28,12 +28,6 @@ impl TaskpanesRels { } } -impl Default for TaskpanesRels { - fn default() -> Self { - TaskpanesRels { rels: Vec::new() } - } -} - impl BuildXML for TaskpanesRels { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/web_settings.rs b/docx-core/src/documents/web_settings.rs index 5cbf41b..2d69647 100644 --- a/docx-core/src/documents/web_settings.rs +++ b/docx-core/src/documents/web_settings.rs @@ -2,7 +2,7 @@ use serde::Serialize; use super::*; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct WebSettings { pub divs: Vec
, @@ -13,9 +13,3 @@ impl WebSettings { Default::default() } } - -impl Default for WebSettings { - fn default() -> Self { - Self { divs: vec![] } - } -} diff --git a/docx-core/src/lib.rs b/docx-core/src/lib.rs index 25823f2..8966402 100644 --- a/docx-core/src/lib.rs +++ b/docx-core/src/lib.rs @@ -1,4 +1,5 @@ mod documents; +#[allow(hidden_glob_reexports)] // should rename? mod errors; mod escape; mod reader; diff --git a/docx-core/src/reader/attributes/bool_value.rs b/docx-core/src/reader/attributes/bool_value.rs index 8b20f99..56618db 100644 --- a/docx-core/src/reader/attributes/bool_value.rs +++ b/docx-core/src/reader/attributes/bool_value.rs @@ -5,7 +5,7 @@ pub fn is_false(v: &str) -> bool { } pub fn read_bool(attrs: &[OwnedAttribute]) -> bool { - if let Some(v) = attrs.get(0) { + if let Some(v) = attrs.first() { if is_false(&v.value) { return false; } diff --git a/docx-core/src/reader/mod.rs b/docx-core/src/reader/mod.rs index 0d544ff..fa30d6b 100644 --- a/docx-core/src/reader/mod.rs +++ b/docx-core/src/reader/mod.rs @@ -76,7 +76,6 @@ pub use attributes::*; pub use document_rels::*; pub use errors::ReaderError; pub use from_xml::*; -pub use mc_fallback::*; pub use read_zip::*; pub use xml_element::*; use zip::ZipArchive; @@ -222,7 +221,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read commentsExtended let comments_extended_path = rels.find_target_path(COMMENTS_EXTENDED_TYPE); let comments_extended = if let Some(comments_extended_path) = comments_extended_path { - if let Some((_, comments_extended_path, ..)) = comments_extended_path.get(0) { + if let Some((_, comments_extended_path, ..)) = comments_extended_path.first() { let data = read_zip( &mut archive, comments_extended_path @@ -244,7 +243,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read comments let comments_path = rels.find_target_path(COMMENTS_TYPE); let comments = if let Some(paths) = comments_path { - if let Some((_, comments_path, ..)) = paths.get(0) { + if let Some((_, comments_path, ..)) = paths.first() { let data = read_zip( &mut archive, comments_path.to_str().expect("should have comments."), @@ -399,7 +398,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read styles let style_path = rels.find_target_path(STYLE_RELATIONSHIP_TYPE); if let Some(paths) = style_path { - if let Some((_, style_path, ..)) = paths.get(0) { + if let Some((_, style_path, ..)) = paths.first() { let data = read_zip( &mut archive, style_path.to_str().expect("should have styles"), @@ -412,7 +411,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read numberings let num_path = rels.find_target_path(NUMBERING_RELATIONSHIP_TYPE); if let Some(paths) = num_path { - if let Some((_, num_path, ..)) = paths.get(0) { + if let Some((_, num_path, ..)) = paths.first() { let data = read_zip( &mut archive, num_path.to_str().expect("should have numberings"), @@ -425,7 +424,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read settings let settings_path = rels.find_target_path(SETTINGS_TYPE); if let Some(paths) = settings_path { - if let Some((_, settings_path, ..)) = paths.get(0) { + if let Some((_, settings_path, ..)) = paths.first() { let data = read_zip( &mut archive, settings_path.to_str().expect("should have settings"), @@ -438,7 +437,7 @@ pub fn read_docx(buf: &[u8]) -> Result { // Read web settings let web_settings_path = rels.find_target_path(WEB_SETTINGS_TYPE); if let Some(paths) = web_settings_path { - if let Some((_, web_settings_path, ..)) = paths.get(0) { + if let Some((_, web_settings_path, ..)) = paths.first() { let data = read_zip( &mut archive, web_settings_path diff --git a/docx-core/src/reader/run.rs b/docx-core/src/reader/run.rs index 4970b59..1fa3946 100644 --- a/docx-core/src/reader/run.rs +++ b/docx-core/src/reader/run.rs @@ -91,7 +91,7 @@ impl ElementReader for Run { XMLElement::Text => text_state = TextState::Text, XMLElement::DeleteText => text_state = TextState::Delete, XMLElement::Break => { - if let Some(a) = &attributes.get(0) { + if let Some(a) = attributes.first() { run = run.add_break(BreakType::from_str(&a.value)?) } else { run = run.add_break(BreakType::TextWrapping) diff --git a/docx-core/src/reader/run_property.rs b/docx-core/src/reader/run_property.rs index 34ad090..9ae5a0e 100644 --- a/docx-core/src/reader/run_property.rs +++ b/docx-core/src/reader/run_property.rs @@ -113,7 +113,7 @@ impl ElementReader for RunProperty { rp = rp.fonts(f); } } - XMLElement::Underline => rp = rp.underline(&attributes[0].value.clone()), + XMLElement::Underline => rp = rp.underline(attributes[0].value.clone()), XMLElement::Italic => { if !read_bool(&attributes) { rp = rp.disable_italic(); diff --git a/docx-core/src/reader/settings.rs b/docx-core/src/reader/settings.rs index e30eb2e..52f19f4 100644 --- a/docx-core/src/reader/settings.rs +++ b/docx-core/src/reader/settings.rs @@ -26,7 +26,7 @@ impl FromXML for Settings { // Ignore w14:val if local_name == "val" && prefix == "w15" { settings = settings.doc_id( - &a.value.to_owned().replace("{", "").replace("}", ""), + a.value.to_owned().replace("{", "").replace("}", ""), ); } } diff --git a/docx-core/src/reader/style.rs b/docx-core/src/reader/style.rs index b29c716..f9b1b1b 100644 --- a/docx-core/src/reader/style.rs +++ b/docx-core/src/reader/style.rs @@ -33,7 +33,7 @@ impl ElementReader for Style { let e = XMLElement::from_str(&name.local_name).unwrap(); match e { XMLElement::Name => { - style = style.name(&attributes[0].value.clone()); + style = style.name(attributes[0].value.clone()); continue; } XMLElement::BasedOn => { diff --git a/docx-core/src/reader/table_cell_property.rs b/docx-core/src/reader/table_cell_property.rs index 5799224..c193e4b 100644 --- a/docx-core/src/reader/table_cell_property.rs +++ b/docx-core/src/reader/table_cell_property.rs @@ -34,12 +34,12 @@ impl ElementReader for TableCellProperty { property = property.width(w, width_type); } XMLElement::TableGridSpan => { - if let Some(a) = &attributes.get(0) { + if let Some(a) = attributes.first() { property = property.grid_span(usize::from_str(&a.value)?) } } XMLElement::TableVMerge => { - if let Some(a) = &attributes.get(0) { + if let Some(a) = attributes.first() { property = property.vertical_merge(VMergeType::from_str(&a.value)?); } else { // Treat as a continue without attribute @@ -47,7 +47,7 @@ impl ElementReader for TableCellProperty { } } XMLElement::VAlign => { - if let Some(a) = &attributes.get(0) { + if let Some(a) = attributes.first() { property = property.vertical_align(VAlignType::from_str(&a.value)?); } } @@ -57,7 +57,7 @@ impl ElementReader for TableCellProperty { } } XMLElement::TextDirection => { - if let Some(a) = &attributes.get(0) { + if let Some(a) = attributes.first() { if let Ok(v) = TextDirectionType::from_str(&a.value) { property = property.text_direction(v); } diff --git a/docx-core/src/xml_builder/macros.rs b/docx-core/src/xml_builder/macros.rs index 7514c5c..fe97d26 100644 --- a/docx-core/src/xml_builder/macros.rs +++ b/docx-core/src/xml_builder/macros.rs @@ -573,7 +573,7 @@ macro_rules! closed_border_el { macro_rules! closed_paragraph_border_el { ($name: ident, $ el_name: expr) => { - pub(crate) fn $name<'a>(mut self, val: &str, space: &str, size: &str, color: &str) -> Self { + pub(crate) fn $name(mut self, val: &str, space: &str, size: &str, color: &str) -> Self { self.writer .write( XmlEvent::start_element($el_name) diff --git a/docx-core/src/xml_builder/mod.rs b/docx-core/src/xml_builder/mod.rs index b5eff06..7a8405b 100644 --- a/docx-core/src/xml_builder/mod.rs +++ b/docx-core/src/xml_builder/mod.rs @@ -27,8 +27,6 @@ use std::str; use xml::common::XmlVersion; use xml::writer::{EmitterConfig, EventWriter, XmlEvent}; -pub use elements::*; - pub struct XMLBuilder { writer: EventWriter>, } diff --git a/docx-core/src/xml_json/mod.rs b/docx-core/src/xml_json/mod.rs index 350de50..5e595e2 100644 --- a/docx-core/src/xml_json/mod.rs +++ b/docx-core/src/xml_json/mod.rs @@ -69,14 +69,13 @@ pub struct XmlData { // Get the attributes as a string fn attributes_to_string(attributes: &[(String, String)]) -> String { - attributes - .iter() - .fold(String::new(), |acc, &(ref k, ref v)| { - format!("{} {}=\"{}\"", acc, k, v) - }) + attributes.iter().fold(String::new(), |acc, (k, v)| { + format!("{} {}=\"{}\"", acc, k, v) + }) } // Format the XML data as a string +#[allow(clippy::only_used_in_recursion)] fn format(data: &XmlData, depth: usize) -> String { let sub = if data.children.is_empty() { String::new() @@ -88,8 +87,6 @@ fn format(data: &XmlData, depth: usize) -> String { sub }; - // let indt = indent(depth); - let fmt_data = if let Some(ref d) = data.data { format!("\n{}", d) } else { diff --git a/rust-toolchain b/rust-toolchain index 5d7eb06..a98f408 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.73 \ No newline at end of file +1.82 \ No newline at end of file