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 {
+10 -21
View File
@@ -118,8 +118,7 @@ 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()),
@@ -146,12 +145,10 @@ impl Operation for AddTier {
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.to_string()), format!("tier add failed. {}", err),
)); ));
} }
} }
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("TierAddFailed".into()), "tier save failed")); return Err(S3Error::with_message(S3ErrorCode::Custom("TierAddFailed".into()), "tier save failed"));
@@ -203,8 +200,7 @@ 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 {
@@ -216,12 +212,10 @@ impl Operation for EditTier {
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.to_string()), format!("tier edit failed. {}", err),
)); ));
} }
} }
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("TierEditFailed".into()), "tier save failed")); return Err(S3Error::with_message(S3ErrorCode::Custom("TierEditFailed".into()), "tier save failed"));
@@ -304,8 +298,7 @@ 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 {
@@ -314,12 +307,11 @@ impl Operation for RemoveTier {
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.to_string()), format!("tier remove failed. {}", err),
)); ));
} }
} }
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,16 +430,13 @@ 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.to_string()), format!("tier clear failed. {}", err),
)); ));
} }
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("TierEditFailed".into()), "tier save failed")); return Err(S3Error::with_message(S3ErrorCode::Custom("TierEditFailed".into()), "tier save failed"));