Skip to content

Commit c406ff4

Browse files
committed
switch to Rust 2024
1 parent a384cc1 commit c406ff4

16 files changed

+37
-46
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ authors = [
99
"rhysd <lin90162@yahoo.co.jp>",
1010
"Andriy Rakhnin <a@rakhnin.com>",
1111
]
12-
edition = "2021"
12+
edition = "2024"
1313
description = "CLI tool for saving web pages as a single HTML file"
1414
homepage = "https://github.com/Y2Z/monolith"
1515
repository = "https://github.com/Y2Z/monolith"

src/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88
use encoding_rs::Encoding;
99
use markup5ever_rcdom::RcDom;
1010
use reqwest::blocking::Client;
11-
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT};
11+
use reqwest::header::{CONTENT_TYPE, COOKIE, HeaderMap, HeaderValue, REFERER, USER_AGENT};
1212
use url::Url;
1313

1414
use crate::cache::Cache;

src/css.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use cssparser::{
2-
serialize_identifier, serialize_string, ParseError, Parser, ParserInput, SourcePosition, Token,
2+
ParseError, Parser, ParserInput, SourcePosition, Token, serialize_identifier, serialize_string,
33
};
44
use reqwest::blocking::Client;
55
use url::Url;
66

77
use crate::cache::Cache;
8-
use crate::core::{retrieve_asset, Options};
9-
use crate::url::{create_data_url, resolve_url, EMPTY_IMAGE_DATA_URL};
8+
use crate::core::{Options, retrieve_asset};
9+
use crate::url::{EMPTY_IMAGE_DATA_URL, create_data_url, resolve_url};
1010

1111
const CSS_PROPS_WITH_IMAGE_URLS: &[&str] = &[
1212
// Universal

src/html.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ use chrono::prelude::*;
33
use encoding_rs::Encoding;
44
use html5ever::interface::QualName;
55
use html5ever::parse_document;
6-
use html5ever::serialize::{serialize, SerializeOpts};
7-
use html5ever::tendril::{format_tendril, TendrilSink};
6+
use html5ever::serialize::{SerializeOpts, serialize};
7+
use html5ever::tendril::{TendrilSink, format_tendril};
88
use html5ever::tree_builder::{Attribute, TreeSink};
9-
use html5ever::{local_name, namespace_url, ns, LocalName};
9+
use html5ever::{LocalName, local_name, namespace_url, ns};
1010
use markup5ever_rcdom::{Handle, NodeData, RcDom, SerializableHandle};
1111
use regex::Regex;
12-
use reqwest::blocking::Client;
1312
use reqwest::Url;
13+
use reqwest::blocking::Client;
1414
use sha2::{Digest, Sha256, Sha384, Sha512};
1515
use std::default::Default;
1616

1717
use crate::cache::Cache;
18-
use crate::core::{parse_content_type, retrieve_asset, Options};
18+
use crate::core::{Options, parse_content_type, retrieve_asset};
1919
use crate::css::embed_css;
2020
use crate::js::attr_is_event_handler;
2121
use crate::url::{
22-
clean_url, create_data_url, is_url_and_has_protocol, resolve_url, EMPTY_IMAGE_DATA_URL,
22+
EMPTY_IMAGE_DATA_URL, clean_url, create_data_url, is_url_and_has_protocol, resolve_url,
2323
};
2424

2525
#[derive(PartialEq, Eq)]
@@ -139,7 +139,7 @@ pub fn create_metadata_tag(url: &Url) -> String {
139139
format!(
140140
"<!-- Saved from {} at {} using {} v{} -->",
141141
if clean_url.scheme() == "http" || clean_url.scheme() == "https" {
142-
&clean_url.as_str()
142+
clean_url.as_str()
143143
} else {
144144
"local source"
145145
},
@@ -357,7 +357,7 @@ pub fn get_child_node_by_name(parent: &Handle, node_name: &str) -> Option<Handle
357357

358358
pub fn get_node_attr(node: &Handle, attr_name: &str) -> Option<String> {
359359
match &node.data {
360-
NodeData::Element { ref attrs, .. } => {
360+
NodeData::Element { attrs, .. } => {
361361
for attr in attrs.borrow().iter() {
362362
if &*attr.name.local == attr_name {
363363
return Some(attr.value.to_string());
@@ -371,7 +371,7 @@ pub fn get_node_attr(node: &Handle, attr_name: &str) -> Option<String> {
371371

372372
pub fn get_node_name(node: &Handle) -> Option<&'_ str> {
373373
match &node.data {
374-
NodeData::Element { ref name, .. } => Some(name.local.as_ref()),
374+
NodeData::Element { name, .. } => Some(name.local.as_ref()),
375375
_ => None,
376376
}
377377
}
@@ -534,7 +534,7 @@ pub fn set_charset(mut dom: RcDom, desired_charset: String) -> RcDom {
534534

535535
pub fn set_node_attr(node: &Handle, attr_name: &str, attr_value: Option<String>) {
536536
match &node.data {
537-
NodeData::Element { ref attrs, .. } => {
537+
NodeData::Element { attrs, .. } => {
538538
let attrs_mut = &mut attrs.borrow_mut();
539539
let mut i = 0;
540540
let mut found_existing_attr: bool = false;

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tempfile::Builder;
88

99
use monolith::cache::Cache;
1010
use monolith::cookies::parse_cookie_file_contents;
11-
use monolith::core::{create_monolithic_document, Options};
11+
use monolith::core::{Options, create_monolithic_document};
1212

1313
enum Output {
1414
Stdout(io::Stdout),

tests/cli/local_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod passing {
1010
use assert_cmd::prelude::*;
1111
use std::env;
1212
use std::fs;
13-
use std::path::{Path, MAIN_SEPARATOR};
13+
use std::path::{MAIN_SEPARATOR, Path};
1414
use std::process::Command;
1515
use url::Url;
1616

tests/core/retrieve_asset.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
#[cfg(test)]
99
mod passing {
10-
use reqwest::blocking::Client;
1110
use reqwest::Url;
11+
use reqwest::blocking::Client;
1212
use std::env;
1313

1414
use monolith::cache::Cache;
15-
use monolith::core::{retrieve_asset, Options};
15+
use monolith::core::{Options, retrieve_asset};
1616
use monolith::url;
1717

1818
#[test]
@@ -99,11 +99,11 @@ mod passing {
9999

100100
#[cfg(test)]
101101
mod failing {
102-
use reqwest::blocking::Client;
103102
use reqwest::Url;
103+
use reqwest::blocking::Client;
104104

105105
use monolith::cache::Cache;
106-
use monolith::core::{retrieve_asset, Options};
106+
use monolith::core::{Options, retrieve_asset};
107107

108108
#[test]
109109
fn read_local_file_with_data_url_parent() {

tests/css/embed_css.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#[cfg(test)]
99
mod passing {
10-
use reqwest::blocking::Client;
1110
use reqwest::Url;
11+
use reqwest::blocking::Client;
1212

1313
use monolith::cache::Cache;
1414
use monolith::core::Options;

tests/html/add_favicon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#[cfg(test)]
99
mod passing {
10-
use html5ever::serialize::{serialize, SerializeOpts};
10+
use html5ever::serialize::{SerializeOpts, serialize};
1111
use markup5ever_rcdom::SerializableHandle;
1212

1313
use monolith::html;

tests/html/compose_csp.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ mod passing {
7878
options.no_images = true;
7979
let csp_content = html::compose_csp(&options);
8080

81-
assert_eq!(csp_content, "default-src 'unsafe-eval' 'unsafe-inline' data:; style-src 'none'; font-src 'none'; frame-src 'none'; child-src 'none'; script-src 'none'; img-src data:;");
81+
assert_eq!(
82+
csp_content,
83+
"default-src 'unsafe-eval' 'unsafe-inline' data:; style-src 'none'; font-src 'none'; frame-src 'none'; child-src 'none'; script-src 'none'; img-src data:;"
84+
);
8285
}
8386
}

0 commit comments

Comments
 (0)