From 378967e989b854c214a42df2b98b7255b2d1cef8 Mon Sep 17 00:00:00 2001 From: John <16479678+john-cd@users.noreply.github.com> Date: Thu, 5 Dec 2024 06:34:29 +0000 Subject: [PATCH] migrate to Rust edition 2024 --- Cargo.lock | 4 ++-- Cargo.toml | 46 +++++++++++++++++++++++----------------------- src/sitemap/xml.rs | 26 ++++++++++---------------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84e656a..3b924bb 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,9 +599,9 @@ checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" [[package]] name = "quick-xml" -version = "0.36.2" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe" +checksum = "f22f29bdff3987b4d8632ef95fd6424ec7e4e0a57e2f4fc63e489e75357f6a03" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index efde9e7..a20b636 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ name = "mdbook-utils" version = "0.1.4" authors = ["John CD"] -edition = "2021" -rust-version = "1.83" +edition = "2024" +rust-version = "1.85" description = "Tools to manage links, reference definitions, and code examples in Markdown files, especially `mdbook` source directories." readme = "README.md" homepage = "https://john-cd.com/mdbook-utils/" @@ -34,29 +34,29 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1" -cargo_toml = "0.20" -clap = { version = "4", features = ["derive"] } -console = "0.15" -csv = "1" -dialoguer = { version = "0.11", features = ["history", "completion"] } -dotenvy = "0.15" -enumflags2 = "0.7" -envy = "0.4" -heck = "0.5" -once_cell = "1.20" -pulldown-cmark = "0.12" +anyhow = "1.0.94" +cargo_toml = "0.20.5" +clap = { version = "4.5.22", features = ["derive"] } +console = "0.15.8" +csv = "1.3.1" +dialoguer = { version = "0.11.0", features = ["history", "completion"] } +dotenvy = "0.15.7" +enumflags2 = "0.7.10" +envy = "0.4.2" +heck = "0.5.0" +once_cell = "1.20.2" +pulldown-cmark = "0.12.2" # pulldown-cmark = { version = "0.12", default-features = false, features = ["simd"] } # pulldown-cmark-to-cmark = "11" -quick-xml = "0.36" -rand = "0.8" -regex = "1.11" -serde = { version = "1", features = ["derive"] } -toml = { version = "0.8", features = ["parse"] } -tracing = "0.1" -tracing-subscriber = "0.3" -url = "2" -walkdir = "2" +quick-xml = "0.37.1" +rand = "0.8.5" +regex = "1.11.1" +serde = { version = "1.0.215", features = ["derive"] } +toml = { version = "0.8.19", features = ["parse"] } +tracing = "0.1.41" +tracing-subscriber = "0.3.19" +url = "2.5.4" +walkdir = "2.5.0" [[bin]] doc = false diff --git a/src/sitemap/xml.rs b/src/sitemap/xml.rs index ac1cc17..0a133d2 100755 --- a/src/sitemap/xml.rs +++ b/src/sitemap/xml.rs @@ -6,24 +6,22 @@ use std::io::Write; -use anyhow::Context; -use anyhow::Error; -use anyhow::Result; +use anyhow::anyhow; use quick_xml::events::BytesText; use quick_xml::writer::Writer; // Write in the sitemap.xml format to a file, given a list of links. -pub(super) fn write_xml(links: Vec, w: &mut W) -> Result<()> { +pub(super) fn write_xml(links: Vec, w: &mut W) -> anyhow::Result<()> { let mut writer = Writer::new_with_indent(w, b' ', 2); writer .write_bom() - .context("[write_xml] Failed to write byte-order-marks to the XML document.")?; + .map_err(|_e| anyhow!("[write_xml] Failed to write byte-order-marks to the XML document."))?; // Insert writer .get_mut() .write_all(b"\n") - .context("[write_xml] Failed to write to the XML document.")?; + .map_err(|_e| anyhow!("[write_xml] Failed to write to the XML document."))?; // writer .create_element("urlset") @@ -35,17 +33,13 @@ pub(super) fn write_xml(links: Vec, w: &mut W) -> Result<()> { .create_element("url") .write_inner_content(|w| { w.create_element("loc") - .write_text_content(BytesText::new(link.as_str())) - .context( - "[write_xml] Failed to write element to the XML document.", - )?; - Ok::<_, Error>(()) - }) - .context("[write_xml] Failed to write element to the XML document.")?; + .write_text_content(BytesText::new(link.as_str()))?; + Ok(()) + })?; } - Ok::<_, Error>(()) - })?; - Ok::<_, Error>(()) + Ok(()) + }).map_err(|_e| anyhow!("[write_xml] Failed to write the url set."))?; + Ok(()) } #[cfg(test)]