prefer unwrap_or_default to unwrap_or
This commit is contained in:
parent
ce03e0e487
commit
84c13f0605
@ -58,7 +58,7 @@ impl AppArgs {
|
|||||||
app_args.output = app.value_of("output").unwrap_or("").to_string();
|
app_args.output = app.value_of("output").unwrap_or("").to_string();
|
||||||
app_args.user_agent = app
|
app_args.user_agent = app
|
||||||
.value_of("user-agent")
|
.value_of("user-agent")
|
||||||
.unwrap_or_else(|| DEFAULT_USER_AGENT)
|
.unwrap_or(DEFAULT_USER_AGENT)
|
||||||
.to_string();
|
.to_string();
|
||||||
app_args
|
app_args
|
||||||
}
|
}
|
||||||
|
30
src/html.rs
30
src/html.rs
@ -111,9 +111,8 @@ pub fn walk_and_embed_assets(
|
|||||||
if opt_no_images {
|
if opt_no_images {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
} else {
|
} else {
|
||||||
let href_full_url: String =
|
let href_full_url = resolve_url(&url, &attr.value.to_string())
|
||||||
resolve_url(&url, &attr.value.to_string())
|
.unwrap_or_default();
|
||||||
.unwrap_or(str!());
|
|
||||||
let (favicon_dataurl, _) = retrieve_asset(
|
let (favicon_dataurl, _) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -122,7 +121,7 @@ pub fn walk_and_embed_assets(
|
|||||||
"",
|
"",
|
||||||
opt_silent,
|
opt_silent,
|
||||||
)
|
)
|
||||||
.unwrap_or((str!(), str!()));
|
.unwrap_or_default();
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(favicon_dataurl.as_str());
|
attr.value.push_slice(favicon_dataurl.as_str());
|
||||||
}
|
}
|
||||||
@ -134,9 +133,8 @@ pub fn walk_and_embed_assets(
|
|||||||
if opt_no_css {
|
if opt_no_css {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
} else {
|
} else {
|
||||||
let href_full_url: String =
|
let href_full_url = resolve_url(&url, &attr.value.to_string())
|
||||||
resolve_url(&url, &attr.value.to_string())
|
.unwrap_or_default();
|
||||||
.unwrap_or(str!());
|
|
||||||
let replacement_text = match retrieve_asset(
|
let replacement_text = match retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -173,8 +171,8 @@ pub fn walk_and_embed_assets(
|
|||||||
} else {
|
} else {
|
||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "href" {
|
if &attr.name.local == "href" {
|
||||||
let href_full_url: String =
|
let href_full_url =
|
||||||
resolve_url(&url, &attr.value.to_string()).unwrap_or(str!());
|
resolve_url(&url, &attr.value.to_string()).unwrap_or_default();
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(&href_full_url.as_str());
|
attr.value.push_slice(&href_full_url.as_str());
|
||||||
}
|
}
|
||||||
@ -244,7 +242,7 @@ pub fn walk_and_embed_assets(
|
|||||||
} else {
|
} else {
|
||||||
let srcset_full_url: String =
|
let srcset_full_url: String =
|
||||||
resolve_url(&url, &attr.value.to_string())
|
resolve_url(&url, &attr.value.to_string())
|
||||||
.unwrap_or(str!());
|
.unwrap_or_default();
|
||||||
let (source_dataurl, _) = retrieve_asset(
|
let (source_dataurl, _) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -270,7 +268,7 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let href_full_url: String =
|
let href_full_url: String =
|
||||||
resolve_url(&url, &attr.value.to_string()).unwrap_or(str!());
|
resolve_url(&url, &attr.value.to_string()).unwrap_or_default();
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(href_full_url.as_str());
|
attr.value.push_slice(href_full_url.as_str());
|
||||||
}
|
}
|
||||||
@ -300,7 +298,7 @@ pub fn walk_and_embed_assets(
|
|||||||
for attr in attrs_mut.iter_mut() {
|
for attr in attrs_mut.iter_mut() {
|
||||||
if &attr.name.local == "src" {
|
if &attr.name.local == "src" {
|
||||||
let src_full_url: String =
|
let src_full_url: String =
|
||||||
resolve_url(&url, &attr.value.to_string()).unwrap_or(str!());
|
resolve_url(&url, &attr.value.to_string()).unwrap_or_default();
|
||||||
let (js_dataurl, _) = retrieve_asset(
|
let (js_dataurl, _) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -345,7 +343,7 @@ pub fn walk_and_embed_assets(
|
|||||||
// Modify action to be a full URL
|
// Modify action to be a full URL
|
||||||
if !is_valid_url(&attr.value) {
|
if !is_valid_url(&attr.value) {
|
||||||
let href_full_url: String =
|
let href_full_url: String =
|
||||||
resolve_url(&url, &attr.value.to_string()).unwrap_or(str!());
|
resolve_url(&url, &attr.value.to_string()).unwrap_or_default();
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(href_full_url.as_str());
|
attr.value.push_slice(href_full_url.as_str());
|
||||||
}
|
}
|
||||||
@ -369,7 +367,7 @@ pub fn walk_and_embed_assets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let src_full_url: String =
|
let src_full_url: String =
|
||||||
resolve_url(&url, &iframe_src).unwrap_or(str!());
|
resolve_url(&url, &iframe_src).unwrap_or_default();
|
||||||
let (iframe_data, iframe_final_url) = retrieve_asset(
|
let (iframe_data, iframe_final_url) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
@ -412,8 +410,8 @@ pub fn walk_and_embed_assets(
|
|||||||
if opt_no_images {
|
if opt_no_images {
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
} else {
|
} else {
|
||||||
let poster_full_url: String =
|
let poster_full_url =
|
||||||
resolve_url(&url, &video_poster).unwrap_or(str!());
|
resolve_url(&url, &video_poster).unwrap_or_default();
|
||||||
let (poster_dataurl, _) = retrieve_asset(
|
let (poster_dataurl, _) = retrieve_asset(
|
||||||
cache,
|
cache,
|
||||||
client,
|
client,
|
||||||
|
Loading…
Reference in New Issue
Block a user