Skip to content

Commit

Permalink
migrate to Rust edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
john-cd committed Dec 5, 2024
1 parent 5661efd commit 378967e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions src/sitemap/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: Write>(links: Vec<String>, w: &mut W) -> Result<()> {
pub(super) fn write_xml<W: Write>(links: Vec<String>, 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 <?xml version="1.0" encoding="UTF-8"?>
writer
.get_mut()
.write_all(b"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.context("[write_xml] Failed to write to the XML document.")?;
.map_err(|_e| anyhow!("[write_xml] Failed to write to the XML document."))?;
// <urlset>
writer
.create_element("urlset")
Expand All @@ -35,17 +33,13 @@ pub(super) fn write_xml<W: Write>(links: Vec<String>, 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 <loc> element to the XML document.",
)?;
Ok::<_, Error>(())
})
.context("[write_xml] Failed to write <url> 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)]
Expand Down

0 comments on commit 378967e

Please sign in to comment.