Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use rust 1.82 and fix clipyy errors #768

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docx-core/src/documents/elements/instr_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -105,6 +106,7 @@ mod tests {

#[test]
fn test_pageref_instr() {
#[allow(unused_allocation)]
let b = Box::new(InstrText::PAGEREF(
InstrPAGEREF::new("_Toc90425847").hyperlink(),
))
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/documents/elements/instr_toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl BuildXML for InstrToC {
fn parse_level_range(i: &str) -> Option<(usize, usize)> {
let r = i.replace("&quot;", "").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) {
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/documents/elements/line_spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
1 change: 0 additions & 1 deletion docx-core/src/documents/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
6 changes: 3 additions & 3 deletions docx-core/src/documents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions docx-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod documents;
#[allow(hidden_glob_reexports)] // should rename?

Check failure on line 2 in docx-core/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

unknown lint: `hidden_glob_reexports`

Check failure on line 2 in docx-core/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

unknown lint: `hidden_glob_reexports`
mod errors;
mod escape;
mod reader;
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/reader/attributes/bool_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions docx-core/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,7 +221,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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
Expand All @@ -244,7 +243,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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."),
Expand Down Expand Up @@ -399,7 +398,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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"),
Expand All @@ -412,7 +411,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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"),
Expand All @@ -425,7 +424,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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"),
Expand All @@ -438,7 +437,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
// 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
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/reader/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/reader/run_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/reader/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("}", ""),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/reader/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
8 changes: 4 additions & 4 deletions docx-core/src/reader/table_cell_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ 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
property = property.vertical_merge(VMergeType::Continue)
}
}
XMLElement::VAlign => {
if let Some(a) = &attributes.get(0) {
if let Some(a) = attributes.first() {
property = property.vertical_align(VAlignType::from_str(&a.value)?);
}
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion docx-core/src/xml_builder/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions docx-core/src/xml_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>>,
}
Expand Down
11 changes: 4 additions & 7 deletions docx-core/src/xml_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@

// 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)]

Check failure on line 78 in docx-core/src/xml_json/mod.rs

View workflow job for this annotation

GitHub Actions / Clippy

unknown lint: `clippy::only_used_in_recursion`
fn format(data: &XmlData, depth: usize) -> String {
let sub = if data.children.is_empty() {
String::new()
Expand All @@ -88,8 +87,6 @@
sub
};

// let indt = indent(depth);

let fmt_data = if let Some(ref d) = data.data {
format!("\n{}", d)
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.73
1.82
Loading