Skip to content

Commit b4584a6

Browse files
committed
fix:polaris-rust clippy
1 parent 2f40561 commit b4584a6

File tree

25 files changed

+224
-200
lines changed

25 files changed

+224
-200
lines changed

src/config/default.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::core::{
3636
use super::{
3737
api::{ConfigFileAPI, ConfigGroupAPI},
3838
req::{
39-
self, CreateConfigFileRequest, GetConfigFileRequest, GetConfigGroupRequest,
39+
CreateConfigFileRequest, GetConfigFileRequest, GetConfigGroupRequest,
4040
PublishConfigFileRequest, UpdateConfigFileRequest, UpsertAndPublishConfigFileRequest,
4141
WatchConfigFileRequest, WatchConfigFileResponse, WatchConfigGroupRequest,
4242
WatchConfigGroupResponse,
@@ -60,9 +60,9 @@ impl ResourceListener for ConfigFileResourceListener {
6060
let mut watch_key = event_key.namespace.clone();
6161
let group = event_key.filter.get("group");
6262
let file = event_key.filter.get("file");
63-
watch_key.push_str("#");
63+
watch_key.push('#');
6464
watch_key.push_str(group.unwrap().as_str());
65-
watch_key.push_str("#");
65+
watch_key.push('#');
6666
watch_key.push_str(file.unwrap().as_str());
6767

6868
let watchers = self.watchers.read().await;
@@ -103,7 +103,7 @@ impl DefaultConfigFileAPI {
103103
pub fn new(context: Arc<SDKContext>, manage_sdk: bool) -> Self {
104104
Self {
105105
context,
106-
manage_sdk: manage_sdk,
106+
manage_sdk,
107107
watchers: Arc::new(ConfigFileResourceListener {
108108
watchers: Arc::new(RwLock::new(HashMap::new())),
109109
}),
@@ -164,7 +164,7 @@ impl ConfigFileAPI for DefaultConfigFileAPI {
164164
let watch_key = req.get_key();
165165
let items = watchers
166166
.entry(watch_key.clone())
167-
.or_insert_with(|| Vec::new());
167+
.or_insert_with(Vec::new);
168168

169169
items.push(ConfigFileWatcher { req });
170170
Ok(WatchConfigFileResponse {})

src/config/req.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl CreateConfigFileRequest {
4242
flow_id = uuid::Uuid::new_v4().to_string();
4343
}
4444
ConfigFileRequest {
45-
flow_id: flow_id,
45+
flow_id,
4646
config_file: self.file.clone(),
4747
}
4848
}
@@ -62,7 +62,7 @@ impl UpdateConfigFileRequest {
6262
flow_id = uuid::Uuid::new_v4().to_string();
6363
}
6464
ConfigFileRequest {
65-
flow_id: flow_id,
65+
flow_id,
6666
config_file: self.file.clone(),
6767
}
6868
}
@@ -82,7 +82,7 @@ impl PublishConfigFileRequest {
8282
flow_id = uuid::Uuid::new_v4().to_string();
8383
}
8484
ConfigReleaseRequest {
85-
flow_id: flow_id,
85+
flow_id,
8686
config_file: self.config_file.clone(),
8787
}
8888
}
@@ -104,7 +104,7 @@ impl UpsertAndPublishConfigFileRequest {
104104
flow_id = uuid::Uuid::new_v4().to_string();
105105
}
106106
ConfigPublishRequest {
107-
flow_id: flow_id,
107+
flow_id,
108108
md5: self.md5.clone(),
109109
release_name: self.release_name.clone(),
110110
config_file: self.config_file.clone(),

src/core/config/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ pub fn load_default<'a>() -> Result<Configuration, io::Error> {
4141
tracing::info!("load config from env: {}", custom_conf_path);
4242
return load(env::var("POLARIS_RUST_CONFIG").unwrap());
4343
}
44-
return load(path);
44+
load(path)
4545
}
4646

4747
pub fn load<P: AsRef<Path>>(path: P) -> Result<Configuration, io::Error> {
4848
let val = fs::read_to_string(path);
4949
if val.is_ok() {
5050
let data = val.ok().unwrap();
5151
let config: Configuration =
52-
serde_yaml::from_str(&*data).expect(&format!("failure to format yaml str {}", &data));
52+
serde_yaml::from_str(&data).unwrap_or_else(|_| panic!("failure to format yaml str {}", &data));
5353
return Ok(config);
5454
}
55-
return Err(val.err().unwrap());
55+
Err(val.err().unwrap())
5656
}
5757

5858
#[cfg(test)]

src/core/config/consumer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::collections::HashMap;
1717

1818
use serde::Deserialize;
1919

20-
use super::global::PluginConfig;
2120

2221
#[derive(Deserialize, Debug)]
2322
#[serde(rename_all = "camelCase", deny_unknown_fields)]

src/core/config/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct ServerConnectorConfig {
8282

8383
impl ServerConnectorConfig {
8484
pub fn get_protocol(&self) -> String {
85-
return self.protocol.clone();
85+
self.protocol.clone()
8686
}
8787

8888
pub fn update_addresses(&mut self, addresses: Vec<String>) {
@@ -125,7 +125,7 @@ fn default_location_providers() -> Vec<LocationProviderConfig> {
125125
name: "local".to_string(),
126126
options: HashMap::new(),
127127
});
128-
return providers;
128+
providers
129129
}
130130

131131
#[derive(Deserialize, Debug, Clone)]

src/core/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use std::sync::Arc;
1717

1818
use crate::core::config::config::{load_default, Configuration};
19-
use crate::core::config::global::{CONFIG_SERVER_CONNECTOR, DISCOVER_SERVER_CONNECTOR};
2019
use crate::core::engine::Engine;
2120
use crate::core::model::error::{ErrorCode, PolarisError};
2221

@@ -29,10 +28,10 @@ impl SDKContext {
2928
// default
3029
pub fn default() -> Result<SDKContext, PolarisError> {
3130
let cfg_opt = load_default();
32-
return match cfg_opt {
31+
match cfg_opt {
3332
Ok(conf) => SDKContext::create_by_configuration(conf),
3433
Err(err) => Err(PolarisError::new(ErrorCode::InternalError, err.to_string())),
35-
};
34+
}
3635
}
3736

3837
// create_by_addresses
@@ -60,10 +59,10 @@ impl SDKContext {
6059
if ret.is_err() {
6160
return Err(ret.err().unwrap());
6261
}
63-
return Ok(Self {
62+
Ok(Self {
6463
conf: cfg,
6564
engine: Arc::new(ret.ok().unwrap()),
66-
});
65+
})
6766
}
6867

6968
pub fn get_engine(&self) -> Arc<Engine> {

src/core/engine.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Engine {
102102
Ok(Self {
103103
runtime,
104104
local_cache: Arc::new(local_cache),
105-
server_connector: server_connector,
105+
server_connector,
106106
location_provider: Arc::new(location_provider),
107107
load_balancer: Arc::new(RwLock::new(extension.load_loadbalancers())),
108108
})
@@ -129,18 +129,18 @@ impl Engine {
129129
}
130130
flow_id
131131
},
132-
ttl: req.ttl.clone(),
133-
instance: instance,
132+
ttl: req.ttl,
133+
instance,
134134
})
135135
.await;
136136

137-
return match rsp {
137+
match rsp {
138138
Ok(ins_rsp) => Ok(InstanceRegisterResponse {
139139
instance_id: ins_rsp.instance.id.clone(),
140-
exist: ins_rsp.exist.clone(),
140+
exist: ins_rsp.exist,
141141
}),
142142
Err(err) => Err(err),
143-
};
143+
}
144144
}
145145

146146
/// deregister_instance 同步注销实例
@@ -163,10 +163,10 @@ impl Engine {
163163
})
164164
.await;
165165

166-
return match rsp {
166+
match rsp {
167167
Ok(_) => Ok(()),
168168
Err(err) => Err(err),
169-
};
169+
}
170170
}
171171

172172
/// instance_heartbeat 同步实例心跳
@@ -189,10 +189,10 @@ impl Engine {
189189
})
190190
.await;
191191

192-
return match rsp {
192+
match rsp {
193193
Ok(_) => Ok(()),
194194
Err(err) => Err(err),
195-
};
195+
}
196196
}
197197

198198
/// get_service_instances 获取服务实例
@@ -210,7 +210,7 @@ impl Engine {
210210
resource_key: ResourceEventKey {
211211
namespace: req.namespace.clone(),
212212
event_type: EventType::Instance,
213-
filter: filter,
213+
filter,
214214
},
215215
internal_request: false,
216216
include_cache: true,
@@ -301,10 +301,10 @@ impl Engine {
301301
let connector = self.server_connector.clone();
302302
let rsp = connector.create_config_file(config_file).await;
303303

304-
return match rsp {
304+
match rsp {
305305
Ok(ret_rsp) => Ok(ret_rsp),
306306
Err(err) => Err(err),
307-
};
307+
}
308308
}
309309

310310
/// update_config_file 更新配置文件
@@ -317,10 +317,10 @@ impl Engine {
317317
let connector = self.server_connector.clone();
318318
let rsp = connector.update_config_file(config_file).await;
319319

320-
return match rsp {
320+
match rsp {
321321
Ok(ret_rsp) => Ok(ret_rsp),
322322
Err(err) => Err(err),
323-
};
323+
}
324324
}
325325

326326
/// publish_config_file 发布配置文件
@@ -333,10 +333,10 @@ impl Engine {
333333
let connector = self.server_connector.clone();
334334
let rsp = connector.release_config_file(config_file).await;
335335

336-
return match rsp {
336+
match rsp {
337337
Ok(ret_rsp) => Ok(ret_rsp),
338338
Err(err) => Err(err),
339-
};
339+
}
340340
}
341341

342342
/// upsert_publish_config_file 更新或发布配置文件
@@ -349,15 +349,15 @@ impl Engine {
349349
let connector = self.server_connector.clone();
350350
let rsp = connector.upsert_publish_config_file(config_file).await;
351351

352-
return match rsp {
352+
match rsp {
353353
Ok(ret_rsp) => Ok(ret_rsp),
354354
Err(err) => Err(err),
355-
};
355+
}
356356
}
357357

358358
pub async fn lookup_loadbalancer(&self, name: &str) -> Option<Arc<Box<dyn LoadBalancer>>> {
359359
let lb = self.load_balancer.read().await;
360-
lb.get(name).map(|lb| lb.clone())
360+
lb.get(name).cloned()
361361
}
362362

363363
/// register_resource_listener 注册资源监听器

0 commit comments

Comments
 (0)