fix: resolve clippy warnings for inherent to_string method shadowing Display trait

This commit is contained in:
weisd
2025-06-30 21:51:19 +08:00
parent 24738dc635
commit e4971b6d83
3 changed files with 74 additions and 79 deletions
+1 -1
View File
@@ -220,7 +220,7 @@ impl TierConfigMgr {
if cfg.is_none() { if cfg.is_none() {
return "internal".to_string(); return "internal".to_string();
} }
cfg.expect("err").tier_type.to_string() cfg.expect("err").tier_type.as_lowercase()
} }
pub fn list_tiers(&self) -> Vec<TierConfig> { pub fn list_tiers(&self) -> Vec<TierConfig> {
+11 -5
View File
@@ -51,7 +51,7 @@ impl TierType {
} }
} }
pub fn to_string(&self) -> String { pub fn as_lowercase(&self) -> String {
match self { match self {
TierType::S3 => "s3".to_string(), TierType::S3 => "s3".to_string(),
TierType::RustFS => "rustfs".to_string(), TierType::RustFS => "rustfs".to_string(),
@@ -199,11 +199,17 @@ pub struct TierS3 {
impl TierS3 { impl TierS3 {
#[allow(dead_code)] #[allow(dead_code)]
fn new<F>(name: &str, access_key: &str, secret_key: &str, bucket: &str, options: Vec<F>) -> Result<TierConfig, std::io::Error> fn create<F>(
name: &str,
access_key: &str,
secret_key: &str,
bucket: &str,
options: Vec<F>,
) -> Result<TierConfig, std::io::Error>
where where
F: Fn(TierS3) -> Box<Result<(), std::io::Error>> + Send + Sync + 'static, F: Fn(TierS3) -> Box<Result<(), std::io::Error>> + Send + Sync + 'static,
{ {
if name == "" { if name.is_empty() {
return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY)); return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY));
} }
let sc = TierS3 { let sc = TierS3 {
@@ -264,7 +270,7 @@ pub struct TierMinIO {
impl TierMinIO { impl TierMinIO {
#[allow(dead_code)] #[allow(dead_code)]
fn new<F>( fn create<F>(
name: &str, name: &str,
endpoint: &str, endpoint: &str,
access_key: &str, access_key: &str,
@@ -275,7 +281,7 @@ impl TierMinIO {
where where
F: Fn(TierMinIO) -> Box<Result<(), std::io::Error>> + Send + Sync + 'static, F: Fn(TierMinIO) -> Box<Result<(), std::io::Error>> + Send + Sync + 'static,
{ {
if name == "" { if name.is_empty() {
return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY)); return Err(std::io::Error::other(ERR_TIER_NAME_EMPTY));
} }
let m = TierMinIO { let m = TierMinIO {
+62 -73
View File
@@ -118,39 +118,36 @@ impl Operation for AddTier {
let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await;
//tier_config_mgr.reload(api); //tier_config_mgr.reload(api);
match tier_config_mgr.add(args, force).await { if let Err(err) = tier_config_mgr.add(args, force).await {
Err(err) => { if err.code == ERR_TIER_ALREADY_EXISTS.code {
if err.code == ERR_TIER_ALREADY_EXISTS.code { return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierNameAlreadyExist".into()),
S3ErrorCode::Custom("TierNameAlreadyExist".into()), "tier name already exists!",
"tier name already exists!", ));
)); } else if err.code == ERR_TIER_NAME_NOT_UPPERCASE.code {
} else if err.code == ERR_TIER_NAME_NOT_UPPERCASE.code { return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierNameNotUppercase".into()),
S3ErrorCode::Custom("TierNameNotUppercase".into()), "tier name not uppercase!",
"tier name not uppercase!", ));
)); } else if err.code == ERR_TIER_BACKEND_IN_USE.code {
} else if err.code == ERR_TIER_BACKEND_IN_USE.code { return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierNameBackendInUse!".into()),
S3ErrorCode::Custom("TierNameBackendInUse!".into()), "tier name backend in use!",
"tier name backend in use!", ));
)); } else if err.code == ERR_TIER_CONNECT_ERR.code {
} else if err.code == ERR_TIER_CONNECT_ERR.code { return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierConnectError".into()),
S3ErrorCode::Custom("TierConnectError".into()), "tier connect error!",
"tier connect error!", ));
)); } else if err.code == ERR_TIER_INVALID_CREDENTIALS.code {
} else if err.code == ERR_TIER_INVALID_CREDENTIALS.code { return Err(S3Error::with_message(S3ErrorCode::Custom(err.code.clone().into()), err.message.clone()));
return Err(S3Error::with_message(S3ErrorCode::Custom(err.code.clone().into()), err.message.clone())); } else {
} else { warn!("tier_config_mgr add failed, e: {:?}", err);
warn!("tier_config_mgr add failed, e: {:?}", err); return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierAddFailed".into()),
S3ErrorCode::Custom("TierAddFailed".into()), format!("tier add failed. {}", err),
format!("tier add failed. {}", err.to_string()), ));
));
}
} }
Ok(_) => (),
} }
if let Err(e) = tier_config_mgr.save().await { if let Err(e) = tier_config_mgr.save().await {
warn!("tier_config_mgr save failed, e: {:?}", e); warn!("tier_config_mgr save failed, e: {:?}", e);
@@ -203,24 +200,21 @@ impl Operation for EditTier {
let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await;
//tier_config_mgr.reload(api); //tier_config_mgr.reload(api);
match tier_config_mgr.edit(&tier_name, creds).await { if let Err(err) = tier_config_mgr.edit(&tier_name, creds).await {
Err(err) => { if err.code == ERR_TIER_NOT_FOUND.code {
if err.code == ERR_TIER_NOT_FOUND.code { return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found!"));
return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found!")); } else if err.code == ERR_TIER_MISSING_CREDENTIALS.code {
} else if err.code == ERR_TIER_MISSING_CREDENTIALS.code { return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierMissingCredentials".into()),
S3ErrorCode::Custom("TierMissingCredentials".into()), "tier missing credentials!",
"tier missing credentials!", ));
)); } else {
} else { warn!("tier_config_mgr edit failed, e: {:?}", err);
warn!("tier_config_mgr edit failed, e: {:?}", err); return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierEditFailed".into()),
S3ErrorCode::Custom("TierEditFailed".into()), format!("tier edit failed. {}", err),
format!("tier edit failed. {}", err.to_string()), ));
));
}
} }
Ok(_) => (),
} }
if let Err(e) = tier_config_mgr.save().await { if let Err(e) = tier_config_mgr.save().await {
warn!("tier_config_mgr save failed, e: {:?}", e); warn!("tier_config_mgr save failed, e: {:?}", e);
@@ -304,22 +298,20 @@ impl Operation for RemoveTier {
let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await;
//tier_config_mgr.reload(api); //tier_config_mgr.reload(api);
match tier_config_mgr.remove(&tier_name, force).await { if let Err(err) = tier_config_mgr.remove(&tier_name, force).await {
Err(err) => { if err.code == ERR_TIER_NOT_FOUND.code {
if err.code == ERR_TIER_NOT_FOUND.code { return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found."));
return Err(S3Error::with_message(S3ErrorCode::Custom("TierNotFound".into()), "tier not found.")); } else if err.code == ERR_TIER_BACKEND_NOT_EMPTY.code {
} else if err.code == ERR_TIER_BACKEND_NOT_EMPTY.code { return Err(S3Error::with_message(S3ErrorCode::Custom("TierNameBackendInUse".into()), "tier is used."));
return Err(S3Error::with_message(S3ErrorCode::Custom("TierNameBackendInUse".into()), "tier is used.")); } else {
} else { warn!("tier_config_mgr remove failed, e: {:?}", err);
warn!("tier_config_mgr remove failed, e: {:?}", err); return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierRemoveFailed".into()),
S3ErrorCode::Custom("TierRemoveFailed".into()), format!("tier remove failed. {}", err),
format!("tier remove failed. {}", err.to_string()), ));
));
}
} }
Ok(_) => (),
} }
if let Err(e) = tier_config_mgr.save().await { if let Err(e) = tier_config_mgr.save().await {
warn!("tier_config_mgr save failed, e: {:?}", e); warn!("tier_config_mgr save failed, e: {:?}", e);
return Err(S3Error::with_message(S3ErrorCode::Custom("TierRemoveFailed".into()), "tier save failed")); return Err(S3Error::with_message(S3ErrorCode::Custom("TierRemoveFailed".into()), "tier save failed"));
@@ -422,7 +414,7 @@ impl Operation for ClearTier {
let mut force: bool = false; let mut force: bool = false;
let force_str = query.force; let force_str = query.force;
if force_str != "" { if !force_str.is_empty() {
force = force_str.parse().unwrap(); force = force_str.parse().unwrap();
} }
@@ -438,15 +430,12 @@ impl Operation for ClearTier {
let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await; let mut tier_config_mgr = GLOBAL_TierConfigMgr.write().await;
//tier_config_mgr.reload(api); //tier_config_mgr.reload(api);
match tier_config_mgr.clear_tier(force).await { if let Err(err) = tier_config_mgr.clear_tier(force).await {
Err(err) => { warn!("tier_config_mgr clear failed, e: {:?}", err);
warn!("tier_config_mgr clear failed, e: {:?}", err); return Err(S3Error::with_message(
return Err(S3Error::with_message( S3ErrorCode::Custom("TierClearFailed".into()),
S3ErrorCode::Custom("TierClearFailed".into()), format!("tier clear failed. {}", err),
format!("tier clear failed. {}", err.to_string()), ));
));
}
Ok(_) => (),
} }
if let Err(e) = tier_config_mgr.save().await { if let Err(e) = tier_config_mgr.save().await {
warn!("tier_config_mgr save failed, e: {:?}", e); warn!("tier_config_mgr save failed, e: {:?}", e);