Skip to content

Commit 5f6168b

Browse files
committed
chore: fix clippy issues
Signed-off-by: Xin Liu <sam@secondstate.io>
1 parent 38e510b commit 5f6168b

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/main.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ async fn main() -> Result<(), ServerError> {
9292
info!(target: "stdout", "download_url_prefix: {}", &download_url_prefix);
9393
let download_url_prefix = Url::parse(&download_url_prefix).map_err(|e| {
9494
ServerError::ArgumentError(format!(
95-
"Failed to parse `download_url_prefix` CLI option. Reason: {}",
96-
e
95+
"Failed to parse `download_url_prefix` CLI option. Reason: {e}",
9796
))
9897
})?;
9998
if let Err(e) = DOWNLOAD_URL_PREFIX.set(download_url_prefix) {
100-
let err_msg = format!("Failed to set DOWNLOAD_URL_PREFIX: {}", e);
99+
let err_msg = format!("Failed to set DOWNLOAD_URL_PREFIX: {e}");
101100

102101
error!(target: "stdout", "{}", &err_msg);
103102

@@ -114,12 +113,11 @@ async fn main() -> Result<(), ServerError> {
114113

115114
let download_url_prefix = Url::parse(&ipv4_addr_str).map_err(|e| {
116115
ServerError::Operation(format!(
117-
"Failed to parse `download_url_prefix` CLI option: {}",
118-
e
116+
"Failed to parse `download_url_prefix` CLI option: {e}",
119117
))
120118
})?;
121119
if let Err(e) = DOWNLOAD_URL_PREFIX.set(download_url_prefix) {
122-
let err_msg = format!("Failed to set SOCKET_ADDRESS: {}", e);
120+
let err_msg = format!("Failed to set SOCKET_ADDRESS: {e}");
123121

124122
error!(target: "stdout", "{}", &err_msg);
125123

@@ -133,12 +131,11 @@ async fn main() -> Result<(), ServerError> {
133131

134132
let download_url_prefix = Url::parse(&ipv4_addr_str).map_err(|e| {
135133
ServerError::Operation(format!(
136-
"Failed to parse `download_url_prefix` CLI option: {}",
137-
e
134+
"Failed to parse `download_url_prefix` CLI option: {e}",
138135
))
139136
})?;
140137
if let Err(e) = DOWNLOAD_URL_PREFIX.set(download_url_prefix) {
141-
let err_msg = format!("Failed to set SOCKET_ADDRESS: {}", e);
138+
let err_msg = format!("Failed to set SOCKET_ADDRESS: {e}");
142139

143140
error!(target: "stdout", "{}", &err_msg);
144141

@@ -291,7 +288,7 @@ async fn process_multipart(mut multipart: Multipart) -> Json<IndexResponse> {
291288
results.push(DocumentResult {
292289
filename: None,
293290
status: "failed".to_string(),
294-
error: Some(format!("Failed to read index field: {}", e)),
291+
error: Some(format!("Failed to read index field: {e}")),
295292
});
296293
continue;
297294
}
@@ -502,7 +499,7 @@ async fn process_field_content(
502499
results.push(DocumentResult {
503500
filename,
504501
status: "failed".to_string(),
505-
error: Some(format!("Failed to read file: {}", e)),
502+
error: Some(format!("Failed to read file: {e}")),
506503
});
507504
}
508505
}
@@ -592,7 +589,7 @@ async fn process_json(request: IndexRequest) -> Json<IndexResponse> {
592589
results.push(DocumentResult {
593590
filename,
594591
status: "failed".to_string(),
595-
error: Some(format!("Failed to add to index: {}", e)),
592+
error: Some(format!("Failed to add to index: {e}")),
596593
});
597594
continue;
598595
}
@@ -719,7 +716,7 @@ async fn query_handler(Json(request): Json<QueryRequest>) -> Json<QueryResponse>
719716
let index = match Index::open_in_dir(&index_path) {
720717
Ok(index) => index,
721718
Err(e) => {
722-
let err_msg = format!("Failed to open index: {}", e);
719+
let err_msg = format!("Failed to open index: {e}");
723720

724721
error!("{}", &err_msg);
725722

@@ -755,7 +752,7 @@ async fn query_handler(Json(request): Json<QueryRequest>) -> Json<QueryResponse>
755752
let query = match query_parser.parse_query(&query_str) {
756753
Ok(q) => q,
757754
Err(e) => {
758-
let err_msg = format!("Failed to parse query: {}", e);
755+
let err_msg = format!("Failed to parse query: {e}");
759756

760757
error!("{}", &err_msg);
761758

@@ -771,7 +768,7 @@ async fn query_handler(Json(request): Json<QueryRequest>) -> Json<QueryResponse>
771768
let top_docs = match searcher.search(&query, &TopDocs::with_limit(request.top_k)) {
772769
Ok(docs) => docs,
773770
Err(e) => {
774-
let err_msg = format!("Search failed: {}", e);
771+
let err_msg = format!("Search failed: {e}");
775772

776773
error!("{}", &err_msg);
777774

@@ -832,7 +829,7 @@ async fn download_index_file_handler(
832829

833830
// Check if index exists
834831
if !index_path.exists() {
835-
let err_msg = format!("Index '{}' not found", index_name);
832+
let err_msg = format!("Index '{index_name}' not found");
836833
error!(
837834
index_name = %index_name,
838835
path = %index_path.display(),
@@ -844,7 +841,7 @@ async fn download_index_file_handler(
844841
info!("Found index directory");
845842

846843
// Prepare compression
847-
let compressed_filename = format!("{}.tar.gz", index_name);
844+
let compressed_filename = format!("{index_name}.tar.gz");
848845
let compressed_index_path = index_storage_dir.as_path().join(&compressed_filename);
849846

850847
// check if compressed file exists
@@ -861,7 +858,7 @@ async fn download_index_file_handler(
861858
file
862859
}
863860
Err(e) => {
864-
let err_msg = format!("Failed to create compressed index file: {}", e);
861+
let err_msg = format!("Failed to create compressed index file: {e}");
865862
error!(
866863
error = %e,
867864
path = %compressed_index_path.display(),
@@ -874,7 +871,7 @@ async fn download_index_file_handler(
874871
// Compress directory
875872
let mut builder = tar::Builder::new(file);
876873
if let Err(e) = builder.append_dir_all(".", &index_path) {
877-
let err_msg = format!("Failed to compress index directory: {}", e);
874+
let err_msg = format!("Failed to compress index directory: {e}");
878875
error!(
879876
error = %e,
880877
source = %index_path.display(),
@@ -885,7 +882,7 @@ async fn download_index_file_handler(
885882
}
886883

887884
if let Err(e) = builder.finish() {
888-
let err_msg = format!("Failed to finalize index compression: {}", e);
885+
let err_msg = format!("Failed to finalize index compression: {e}");
889886
error!(
890887
error = %e,
891888
path = %compressed_index_path.display(),
@@ -901,7 +898,7 @@ async fn download_index_file_handler(
901898
let mut file = match File::open(&compressed_index_path) {
902899
Ok(file) => file,
903900
Err(e) => {
904-
let err_msg = format!("Failed to open the compressed file: {}", e);
901+
let err_msg = format!("Failed to open the compressed file: {e}");
905902
error!(
906903
error = %e,
907904
path = %compressed_index_path.display(),
@@ -914,7 +911,7 @@ async fn download_index_file_handler(
914911
// Read file content
915912
let mut buffer: Vec<u8> = Vec::new();
916913
if let Err(e) = file.read_to_end(&mut buffer) {
917-
let err_msg = format!("Failed to read the compressed file content: {}", e);
914+
let err_msg = format!("Failed to read the compressed file content: {e}");
918915
error!(
919916
error = %e,
920917
path = %compressed_index_path.display(),
@@ -925,7 +922,7 @@ async fn download_index_file_handler(
925922

926923
// Prepare response
927924
let content_type = "application/gzip";
928-
let content_disposition = format!("attachment; filename=\"{}\"", compressed_filename);
925+
let content_disposition = format!("attachment; filename=\"{compressed_filename}\"");
929926
let content_length = buffer.len();
930927
let body = axum::body::Body::from(buffer);
931928

@@ -951,7 +948,7 @@ async fn download_index_file_handler(
951948
response
952949
}
953950
Err(e) => {
954-
let err_msg = format!("Failed to build response: {}", e);
951+
let err_msg = format!("Failed to build response: {e}");
955952
error!(
956953
error = %e,
957954
index_name = %index_name,

0 commit comments

Comments
 (0)