mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
fix: remove func call from alternative value.
this avoid useless allocation or non-trivial work, if the default value is not needed/used. add a line in Cargo.toml to easly enable or_fun_call lint help: https://rust-lang.github.io/rust-clippy/master/index.html?search=or_fun_call
This commit is contained in:
@@ -186,3 +186,6 @@ doc_markdown = "warn"
|
||||
manual_midpoint = "warn"
|
||||
semicolon_if_nothing_returned = "warn"
|
||||
unnecessary_semicolon = "warn"
|
||||
|
||||
# nursery lints configuration
|
||||
# or_fun_call = "warn" # enable it to help detect non trivial code used in `_or` method
|
||||
|
||||
@@ -62,7 +62,7 @@ impl Endpoint {
|
||||
let (bucket, partition_key) = path
|
||||
.split_once('/')
|
||||
.map(|(b, p)| (b.to_owned(), p.trim_start_matches('/')))
|
||||
.unwrap_or((path.to_owned(), ""));
|
||||
.unwrap_or_else(|| (path.to_owned(), ""));
|
||||
|
||||
if bucket.is_empty() {
|
||||
return Err(Error::bad_request("Missing bucket name"));
|
||||
|
||||
@@ -494,7 +494,7 @@ pub async fn handle_complete_multipart_upload(
|
||||
.root_domain
|
||||
.as_ref()
|
||||
.map(|rd| s3_xml::Value(format!("https://{}.{}/{}", bucket_name, rd, key)))
|
||||
.or(Some(s3_xml::Value(format!("/{}/{}", bucket_name, key)))),
|
||||
.or_else(|| Some(s3_xml::Value(format!("/{}/{}", bucket_name, key)))),
|
||||
bucket: s3_xml::Value(bucket_name.to_string()),
|
||||
key: s3_xml::Value(key),
|
||||
etag: s3_xml::Value(format!("\"{}\"", etag)),
|
||||
|
||||
@@ -330,7 +330,7 @@ impl Endpoint {
|
||||
} else {
|
||||
path.split_once('/')
|
||||
.map(|(b, p)| (b.to_owned(), p.trim_start_matches('/')))
|
||||
.unwrap_or((path.to_owned(), ""))
|
||||
.unwrap_or_else(|| (path.to_owned(), ""))
|
||||
};
|
||||
|
||||
if *req.method() == Method::OPTIONS {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use format_table::format_table;
|
||||
|
||||
use chrono::Local;
|
||||
@@ -42,18 +44,18 @@ impl Cli {
|
||||
table_list_abbr(&tok.scope)
|
||||
};
|
||||
let exp = if tok.expired {
|
||||
"expired".to_string()
|
||||
Cow::Borrowed("expired")
|
||||
} else {
|
||||
tok.expiration
|
||||
.map(|x| x.with_timezone(&Local).to_string())
|
||||
.unwrap_or("never".into())
|
||||
.map(|x| x.with_timezone(&Local).to_string().into())
|
||||
.unwrap_or(Cow::Borrowed("never"))
|
||||
};
|
||||
table.push(format!(
|
||||
"{}\t{}\t{}\t{}\t{}",
|
||||
tok.id.as_deref().unwrap_or("-"),
|
||||
tok.created
|
||||
.map(|x| x.with_timezone(&Local).date_naive().to_string())
|
||||
.unwrap_or("-".into()),
|
||||
.map(|x| x.with_timezone(&Local).date_naive().to_string().into())
|
||||
.unwrap_or(Cow::Borrowed("-")),
|
||||
tok.name,
|
||||
exp,
|
||||
scope,
|
||||
@@ -236,8 +238,8 @@ fn print_token_info(token: &GetAdminTokenInfoResponse) {
|
||||
"Expiration:\t{}",
|
||||
token
|
||||
.expiration
|
||||
.map(|x| x.with_timezone(&Local).to_string())
|
||||
.unwrap_or("never".into())
|
||||
.map(|x| x.with_timezone(&Local).to_string().into())
|
||||
.unwrap_or(Cow::Borrowed("never"))
|
||||
),
|
||||
String::new(),
|
||||
];
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use format_table::format_table;
|
||||
|
||||
use chrono::Local;
|
||||
@@ -33,11 +35,11 @@ impl Cli {
|
||||
let mut table = vec!["ID\tCreated\tName\tExpiration".to_string()];
|
||||
for key in keys.0.iter() {
|
||||
let exp = if key.expired {
|
||||
"expired".to_string()
|
||||
Cow::from("expired")
|
||||
} else {
|
||||
key.expiration
|
||||
.map(|x| x.with_timezone(&Local).to_string())
|
||||
.unwrap_or("never".into())
|
||||
.map(|x| x.with_timezone(&Local).to_string().into())
|
||||
.unwrap_or(Cow::Borrowed("never"))
|
||||
};
|
||||
table.push(format!(
|
||||
"{}\t{}\t{}\t{}",
|
||||
@@ -288,8 +290,8 @@ fn print_key_info(key: &GetKeyInfoResponse) {
|
||||
format!(
|
||||
"Expiration:\t{}",
|
||||
key.expiration
|
||||
.map(|x| x.with_timezone(&Local).to_string())
|
||||
.unwrap_or("never".into())
|
||||
.map(|x| x.with_timezone(&Local).to_string().into())
|
||||
.unwrap_or(Cow::Borrowed("never"))
|
||||
),
|
||||
String::new(),
|
||||
format!("Can create buckets:\t{}", key.permissions.create_bucket),
|
||||
|
||||
@@ -65,7 +65,11 @@ pub fn register_bg_vars(
|
||||
vars: &mut vars::BgVars,
|
||||
) {
|
||||
vars.register_ro(persister, "lifecycle-last-completed", |p| {
|
||||
p.get_with(|x| x.last_completed.clone().unwrap_or("never".to_string()))
|
||||
p.get_with(|x| {
|
||||
x.last_completed
|
||||
.clone()
|
||||
.unwrap_or_else(|| "never".to_string())
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ impl LayoutHelper {
|
||||
Ok(versions
|
||||
.iter()
|
||||
.find(|x| x.version == sync_min)
|
||||
.or(versions.last())
|
||||
.or_else(|| versions.last())
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ impl LayoutHelper {
|
||||
.map(|x| x.load(Ordering::Relaxed) == 0)
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.unwrap_or(self.inner().current().version);
|
||||
.unwrap_or_else(|| self.inner().current().version);
|
||||
let changed = self.update(|layout| {
|
||||
layout
|
||||
.update_trackers
|
||||
|
||||
Reference in New Issue
Block a user