prefer unwrap_or_default to unwrap_or

pull/96/head
rhysd 4 years ago
parent ce03e0e487
commit 84c13f0605

@ -58,7 +58,7 @@ impl AppArgs {
app_args.output = app.value_of("output").unwrap_or("").to_string();
app_args.user_agent = app
.value_of("user-agent")
.unwrap_or_else(|| DEFAULT_USER_AGENT)
.unwrap_or(DEFAULT_USER_AGENT)
.to_string();
app_args
}

@ -111,9 +111,8 @@ pub fn walk_and_embed_assets(
if opt_no_images {
attr.value.clear();
} else {
let href_full_url: String =
resolve_url(&url, &attr.value.to_string())
.unwrap_or(str!());
let href_full_url = resolve_url(&url, &attr.value.to_string())
.unwrap_or_default();
let (favicon_dataurl, _) = retrieve_asset(
cache,
client,
@ -122,7 +121,7 @@ pub fn walk_and_embed_assets(
"",
opt_silent,
)
.unwrap_or((str!(), str!()));
.unwrap_or_default();
attr.value.clear();
attr.value.push_slice(favicon_dataurl.as_str());
}
@ -134,9 +133,8 @@ pub fn walk_and_embed_assets(
if opt_no_css {
attr.value.clear();
} else {
let href_full_url: String =
resolve_url(&url, &attr.value.to_string())
.unwrap_or(str!());
let href_full_url = resolve_url(&url, &attr.value.to_string())
.unwrap_or_default();
let replacement_text = match retrieve_asset(
cache,
client,
@ -173,8 +171,8 @@ pub fn walk_and_embed_assets(
} else {
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "href" {
let href_full_url: String =
resolve_url(&url, &attr.value.to_string()).unwrap_or(str!());
let href_full_url =
resolve_url(&url, &attr.value.to_string()).unwrap_or_default();
attr.value.clear();
attr.value.push_slice(&href_full_url.as_str());
}
@ -244,7 +242,7 @@ pub fn walk_and_embed_assets(
} else {
let srcset_full_url: String =
resolve_url(&url, &attr.value.to_string())
.unwrap_or(str!());
.unwrap_or_default();
let (source_dataurl, _) = retrieve_asset(
cache,
client,
@ -270,7 +268,7 @@ pub fn walk_and_embed_assets(
}
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.push_slice(href_full_url.as_str());
}
@ -300,7 +298,7 @@ pub fn walk_and_embed_assets(
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "src" {
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(
cache,
client,
@ -345,7 +343,7 @@ pub fn walk_and_embed_assets(
// Modify action to be a full URL
if !is_valid_url(&attr.value) {
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.push_slice(href_full_url.as_str());
}
@ -369,7 +367,7 @@ pub fn walk_and_embed_assets(
}
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(
cache,
client,
@ -412,8 +410,8 @@ pub fn walk_and_embed_assets(
if opt_no_images {
attr.value.clear();
} else {
let poster_full_url: String =
resolve_url(&url, &video_poster).unwrap_or(str!());
let poster_full_url =
resolve_url(&url, &video_poster).unwrap_or_default();
let (poster_dataurl, _) = retrieve_asset(
cache,
client,

Loading…
Cancel
Save