chore (backend-rs): prefer unwrap_or_else

This commit is contained in:
naskya 2024-06-06 17:10:35 +09:00
parent 4b20f397fd
commit b111e63953
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
5 changed files with 9 additions and 9 deletions

View file

@ -293,7 +293,7 @@ pub fn load_config() -> Config {
} else {
server_config.redis.prefix.clone()
}
.unwrap_or(hostname.clone());
.unwrap_or_else(|| hostname.clone());
Config {
url: server_config.url,

View file

@ -66,7 +66,7 @@ async fn generate_nodeinfo_2_1() -> Result<Nodeinfo21, Error> {
let metadata = HashMap::from([
(
"nodeName".to_string(),
json!(meta.name.unwrap_or(CONFIG.host.clone())),
json!(meta.name.unwrap_or_else(|| CONFIG.host.clone())),
),
("nodeDescription".to_string(), json!(meta.description)),
("repositoryUrl".to_string(), json!(meta.repository_url)),
@ -93,7 +93,7 @@ async fn generate_nodeinfo_2_1() -> Result<Nodeinfo21, Error> {
("proxyAccountName".to_string(), json!(meta.proxy_account_id)),
(
"themeColor".to_string(),
json!(meta.theme_color.unwrap_or("#31748f".to_string())),
json!(meta.theme_color.unwrap_or_else(|| "#31748f".to_string())),
),
]);

View file

@ -26,19 +26,19 @@ pub fn show_server_info() -> Result<(), SysinfoPoisonError> {
tracing::info!(
"Hostname: {}",
System::host_name().unwrap_or("unknown".to_string())
System::host_name().unwrap_or_else(|| "unknown".to_string())
);
tracing::info!(
"OS: {}",
System::long_os_version().unwrap_or("unknown".to_string())
System::long_os_version().unwrap_or_else(|| "unknown".to_string())
);
tracing::info!(
"Kernel: {}",
System::kernel_version().unwrap_or("unknown".to_string())
System::kernel_version().unwrap_or_else(|| "unknown".to_string())
);
tracing::info!(
"CPU architecture: {}",
System::cpu_arch().unwrap_or("unknown".to_string())
System::cpu_arch().unwrap_or_else(|| "unknown".to_string())
);
tracing::info!("CPU threads: {}", system_info.cpus().len());
tracing::info!("Total memory: {} MiB", system_info.total_memory() / 1048576);

View file

@ -61,7 +61,7 @@ pub async fn check_hit_antenna(
== note_author
.host
.clone()
.unwrap_or(CONFIG.host.clone())
.unwrap_or_else(|| CONFIG.host.clone())
.to_ascii_lowercase()
});

View file

@ -66,7 +66,7 @@ pub async fn publish_to_stream(
format!(
"{{\"type\":\"{}\",\"body\":{}}}",
kind,
value.unwrap_or("null".to_string()),
value.unwrap_or_else(|| "null".to_string()),
)
} else {
value.ok_or(Error::Value("Invalid streaming message".to_string()))?