-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate to Rust 2024 edition #2587
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cargo +nightly fmt
warning: returning the result of a `let` binding from a block --> src/cmd/snappy.rs:122:13 | 121 | let temp_download_path = temp_download.path().to_str().unwrap().to_string(); | ---------------------------------------------------------------------------- unnecessary `let` binding 122 | temp_download_path | ^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 121 ~ 122 ~ temp_download.path().to_str().unwrap().to_string() | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/stats.rs:970:9 | 970 | / match rconfig.path { 971 | | Some(path) => { 972 | | // if we read from a file, copy the temp stats file to "<FILESTEM>.stats.csv" 973 | | let mut stats_pathbuf = path.clone(); ... | 1037 | | _ => {}, 1038 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 970 ~ if let Some(path) = rconfig.path { 971 + // if we read from a file, copy the temp stats file to "<FILESTEM>.stats.csv" 972 + let mut stats_pathbuf = path.clone(); 973 + stats_pathbuf.set_extension("stats.csv"); 974 + // safety: we know the path is a valid PathBuf, so we can use unwrap 975 + if currstats_filename != stats_pathbuf.to_str().unwrap() { 976 + // if the stats file is not the same as the input file, copy it 977 + fs::copy(currstats_filename.clone(), stats_pathbuf.clone())?; 978 + } 979 + 980 + if args.flag_cache_threshold == 0 981 + || (args.flag_cache_threshold.is_negative() 982 + && args.flag_cache_threshold % 10 == -5) 983 + { 984 + // if the cache threshold zero or is a negative number ending in 5, 985 + // delete both the index file and the stats cache file 986 + if autoindex_set { 987 + let index_file = path.with_extension("csv.idx"); 988 + log::debug!("deleting index file: {}", index_file.display()); 989 + if std::fs::remove_file(index_file.clone()).is_err() { 990 + // fails silently if it can't remove the index file 991 + log::warn!("Could not remove index file: {}", index_file.display()); 992 + } 993 + } 994 + 995 + // remove the stats cache file 996 + if fs::remove_file(stats_pathbuf.clone()).is_err() { 997 + // fails silently if it can't remove the stats file 998 + log::warn!( 999 + "Could not remove stats cache file: {}", 1000 + stats_pathbuf.display() 1001 + ); 1002 + } 1003 + create_cache = false; 1004 + } 1005 + 1006 + if compute_stats && create_cache { 1007 + // save the stats args to "<FILESTEM>.stats.csv.json" 1008 + // if we computed the stats 1009 + stats_pathbuf.set_extension("csv.json"); 1010 + // write empty file first so we can canonicalize it 1011 + std::fs::File::create(stats_pathbuf.clone())?; 1012 + // safety: we know the path is a valid PathBuf, so we can use unwrap 1013 + current_stats_args.canonical_stats_path = stats_pathbuf 1014 + .clone() 1015 + .canonicalize()? 1016 + .to_str() 1017 + .unwrap() 1018 + .to_string(); 1019 + std::fs::write( 1020 + stats_pathbuf.clone(), 1021 + serde_json::to_string_pretty(¤t_stats_args)?, 1022 + )?; 1023 + 1024 + // save the stats data to "<FILESTEM>.stats.csv.data.jsonl" 1025 + if write_stats_jsonl { 1026 + let mut stats_jsonl_pathbuf = stats_pathbuf.clone(); 1027 + stats_jsonl_pathbuf.set_extension("data.jsonl"); 1028 + util::csv_to_jsonl( 1029 + &currstats_filename, 1030 + &STATSDATA_TYPES_MAP, 1031 + &stats_jsonl_pathbuf, 1032 + )?; 1033 + } 1034 + } 1035 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/stats.rs:1047:9 | 1047 | / match args.flag_output { 1048 | | Some(output) => { 1049 | | // if we're outputting to a file, copy the stats file to the output file 1050 | | if currstats_filename != output { ... | 1055 | | _ => {}, 1056 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try | 1047 ~ if let Some(output) = args.flag_output { 1048 + // if we're outputting to a file, copy the stats file to the output file 1049 + if currstats_filename != output { 1050 + // if the stats file is not the same as the output file, copy it 1051 + fs::copy(currstats_filename, output)?; 1052 + } 1053 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/template.rs:573:17 | 573 | / match bulk_wtr { 574 | | Some(ref mut w) => { 575 | | w.write_all(result_record.1.as_bytes())?; 576 | | }, 577 | | _ => {}, 578 | | } | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try | 573 ~ if let Some(ref mut w) = bulk_wtr { 574 + w.write_all(result_record.1.as_bytes())?; 575 + } | warning: returning the result of a `let` binding from a block --> src/odhtcache.rs:174:9 | 164 | / let res = item 165 | | .as_bytes() 166 | | .chunks(CHUNK_SIZE) 167 | | .enumerate() ... | 172 | | key 173 | | }); | |_______________- unnecessary `let` binding 174 | res | ^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return help: return the expression directly | 164 ~ 165 ~ item 166 + .as_bytes() 167 + .chunks(CHUNK_SIZE) 168 + .enumerate() 169 + .map(|(i, chunk)| { 170 + let mut key = [0_u8; CHUNK_SIZE + 1]; 171 + key[CHUNK_SIZE] = i as u8; 172 + key[..chunk.len()].copy_from_slice(chunk); 173 + key 174 + })
warning: this `else { if .. }` block can be collapsed --> src/cmd/stats.rs:969:12 | 969 | } else { | ____________^ 970 | | if let Some(path) = rconfig.path { 971 | | // if we read from a file, copy the temp stats file to "<FILESTEM>.stats.csv" 972 | | let mut stats_pathbuf = path.clone(); ... | 1036 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 969 ~ } else if let Some(path) = rconfig.path { 970 + // if we read from a file, copy the temp stats file to "<FILESTEM>.stats.csv" 971 + let mut stats_pathbuf = path.clone(); 972 + stats_pathbuf.set_extension("stats.csv"); 973 + // safety: we know the path is a valid PathBuf, so we can use unwrap 974 + if currstats_filename != stats_pathbuf.to_str().unwrap() { 975 + // if the stats file is not the same as the input file, copy it 976 + fs::copy(currstats_filename.clone(), stats_pathbuf.clone())?; 977 + } 978 + 979 + if args.flag_cache_threshold == 0 980 + || (args.flag_cache_threshold.is_negative() 981 + && args.flag_cache_threshold % 10 == -5) 982 + { 983 + // if the cache threshold zero or is a negative number ending in 5, 984 + // delete both the index file and the stats cache file 985 + if autoindex_set { 986 + let index_file = path.with_extension("csv.idx"); 987 + log::debug!("deleting index file: {}", index_file.display()); 988 + if std::fs::remove_file(index_file.clone()).is_err() { 989 + // fails silently if it can't remove the index file 990 + log::warn!("Could not remove index file: {}", index_file.display()); 991 + } 992 + } 993 + 994 + // remove the stats cache file 995 + if fs::remove_file(stats_pathbuf.clone()).is_err() { 996 + // fails silently if it can't remove the stats file 997 + log::warn!( 998 + "Could not remove stats cache file: {}", 999 + stats_pathbuf.display() 1000 + ); 1001 + } 1002 + create_cache = false; 1003 + } 1004 + 1005 + if compute_stats && create_cache { 1006 + // save the stats args to "<FILESTEM>.stats.csv.json" 1007 + // if we computed the stats 1008 + stats_pathbuf.set_extension("csv.json"); 1009 + // write empty file first so we can canonicalize it 1010 + std::fs::File::create(stats_pathbuf.clone())?; 1011 + // safety: we know the path is a valid PathBuf, so we can use unwrap 1012 + current_stats_args.canonical_stats_path = stats_pathbuf 1013 + .clone() 1014 + .canonicalize()? 1015 + .to_str() 1016 + .unwrap() 1017 + .to_string(); 1018 + std::fs::write( 1019 + stats_pathbuf.clone(), 1020 + serde_json::to_string_pretty(¤t_stats_args)?, 1021 + )?; 1022 + 1023 + // save the stats data to "<FILESTEM>.stats.csv.data.jsonl" 1024 + if write_stats_jsonl { 1025 + let mut stats_jsonl_pathbuf = stats_pathbuf.clone(); 1026 + stats_jsonl_pathbuf.set_extension("data.jsonl"); 1027 + util::csv_to_jsonl( 1028 + &currstats_filename, 1029 + &STATSDATA_TYPES_MAP, 1030 + &stats_jsonl_pathbuf, 1031 + )?; 1032 + } 1033 + } 1034 + } | warning: this `else { if .. }` block can be collapsed --> src/cmd/stats.rs:1043:12 | 1043 | } else { | ____________^ 1044 | | if let Some(output) = args.flag_output { 1045 | | // if we're outputting to a file, copy the stats file to the output file 1046 | | if currstats_filename != output { ... | 1051 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if help: collapse nested if block | 1043 ~ } else if let Some(output) = args.flag_output { 1044 + // if we're outputting to a file, copy the stats file to the output file 1045 + if currstats_filename != output { 1046 + // if the stats file is not the same as the output file, copy it 1047 + fs::copy(currstats_filename, output)?; 1048 + } 1049 + } | warning: this `else { if .. }` block can be collapsed --> src/cmd/template.rs:572:20 | 572 | } else { | ____________________^ 573 | | if let Some(ref mut w) = bulk_wtr { 574 | | w.write_all(result_record.1.as_bytes())?; 575 | | } 576 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if help: collapse nested if block | 572 ~ } else if let Some(ref mut w) = bulk_wtr { 573 + w.write_all(result_record.1.as_bytes())?; 574 + } | warning: `qsv` (bin "qsv") generated 3 warnings (run `cargo clippy --fix --bin "qsv"` to apply 3 suggestions)
warning: variables can be used directly in the `format!` string --> src/cmd/apply.rs:1194:33 | 1194 | ... format!("{}0", numparts_str) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]` help: change this to | 1194 - format!("{}0", numparts_str) 1194 + format!("{numparts_str}0") | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/describegpt.rs:495:54 | 495 | let completion_json: serde_json::Value = match serde_json::from_str(output) { | ______________________________________________________^ 496 | | Ok(val) => { 497 | | // Output is valid JSON 498 | | val ... | 509 | | }, 510 | | }; | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else = note: `-W clippy::single-match-else` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::single_match_else)]` help: try | 495 ~ let completion_json: serde_json::Value = if let Ok(val) = serde_json::from_str(output) { 496 + // Output is valid JSON 497 + val 498 + } else { 499 + // Output is invalid JSON 500 + // Default error message in JSON format 501 + let error_message = format!("Error: Invalid JSON output for {option}."); 502 + let error_json = json!({"error": error_message}); 503 + // Print error message in JSON format 504 + print_status(args, format!("{error_json}").as_str()); 505 + print_status(args, format!("Output: {output}").as_str()); 506 + error_json 507 ~ }; | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/excel.rs:906:13 | 906 | / match sheets.worksheet_range_at(sheet_index) { 907 | | Some(result) => { 908 | | export_mode = ExportMode::Sheet; 909 | | result? ... | 914 | | }, 915 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 906 ~ if let Some(result) = sheets.worksheet_range_at(sheet_index) { 907 + export_mode = ExportMode::Sheet; 908 + result? 909 + } else { 910 + export_mode = ExportMode::NothingToExport; 911 + Range::empty() 912 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/fetch.rs:518:36 | 518 | let include_existing_columns = match args.flag_new_column { | ____________________________________^ 519 | | Some(name) => { 520 | | // write header with new column 521 | | headers.push_field(name.as_bytes()); ... | 532 | | }, 533 | | }; | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 518 ~ let include_existing_columns = if let Some(name) = args.flag_new_column { 519 + // write header with new column 520 + headers.push_field(name.as_bytes()); 521 + wtr.write_byte_record(&headers)?; 522 + true 523 + } else { 524 + if args.flag_pretty { 525 + return fail_incorrectusage_clierror!( 526 + "The --pretty option requires the --new-column option." 527 + ); 528 + } 529 + false 530 ~ }; | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/fetch.rs:1268:9 | 1268 | / match client.get(&valid_url).send() { 1269 | | Ok(resp) => { 1270 | | // debug!("{resp:?}"); 1271 | | api_respheader.clone_from(resp.headers()); ... | 1344 | | }, 1345 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 1268 ~ if let Ok(resp) = client.get(&valid_url).send() { 1269 + // debug!("{resp:?}"); 1270 + api_respheader.clone_from(resp.headers()); 1271 + api_status = resp.status(); 1272 + api_value = resp.text().unwrap_or_default(); 1273 + 1274 + if api_status.is_client_error() || api_status.is_server_error() { 1275 + error_flag = true; 1276 + error!( 1277 + "HTTP error. url: {valid_url:?}, error: {:?}", 1278 + api_status.canonical_reason().unwrap_or("unknown error") 1279 + ); 1280 + 1281 + if flag_store_error { 1282 + final_value = format!( 1283 + "HTTP ERROR {} - {}", 1284 + api_status.as_str(), 1285 + api_status.canonical_reason().unwrap_or("unknown error") 1286 + ); 1287 + } else { 1288 + final_value = String::new(); 1289 + } 1290 + } else { 1291 + error_flag = false; 1292 + // apply jaq selector if provided 1293 + if let Some(selectors) = flag_jaq { 1294 + match process_jaq(&api_value, selectors) { 1295 + Ok(s) => { 1296 + final_value = s; 1297 + }, 1298 + Err(e) => { 1299 + error!( 1300 + "jaq error. json: {api_value:?}, selectors: {selectors:?}, \ 1301 + error: {e:?}" 1302 + ); 1303 + 1304 + if flag_store_error { 1305 + final_value = e.to_string(); 1306 + } else { 1307 + final_value = String::new(); 1308 + } 1309 + error_flag = true; 1310 + }, 1311 + } 1312 + } else { 1313 + // validate the JSON response 1314 + api_value_json_result = 1315 + serde_json::from_str::<serde_json::Value>(&api_value); 1316 + match api_value_json_result { 1317 + Ok(api_value_json) => { 1318 + if flag_pretty { 1319 + final_value = format!("{api_value_json:#}"); 1320 + } else { 1321 + // use serde_json CompactFormatter to minify the JSON 1322 + final_value = format!("{api_value_json}"); 1323 + } 1324 + }, 1325 + Err(e) => { 1326 + error!("json error. json: {api_value:?}, error: {e:?}"); 1327 + 1328 + if flag_store_error { 1329 + final_value = e.to_string(); 1330 + } else { 1331 + final_value = String::new(); 1332 + } 1333 + error_flag = true; 1334 + }, 1335 + } 1336 + } 1337 + } 1338 + } else { 1339 + error_flag = true; 1340 + api_respheader.clear(); 1341 + api_status = reqwest::StatusCode::BAD_REQUEST; 1342 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/fetchpost.rs:496:36 | 496 | let include_existing_columns = match args.flag_new_column { | ____________________________________^ 497 | | Some(name) => { 498 | | // write header with new column 499 | | headers.push_field(name.as_bytes()); ... | 510 | | }, 511 | | }; | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 496 ~ let include_existing_columns = if let Some(name) = args.flag_new_column { 497 + // write header with new column 498 + headers.push_field(name.as_bytes()); 499 + wtr.write_byte_record(&headers)?; 500 + true 501 + } else { 502 + if args.flag_pretty { 503 + return fail_incorrectusage_clierror!( 504 + "The --pretty option requires the --new-column option." 505 + ); 506 + } 507 + false 508 ~ }; | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/fetchpost.rs:565:23 | 565 | let payload_env = match args.flag_payload_tpl { | _______________________^ 566 | | Some(template_file) => { 567 | | template_content = fs::read_to_string(template_file)?; 568 | | let mut env = Environment::new(); ... | 577 | | }, 578 | | }; | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 565 ~ let payload_env = if let Some(template_file) = args.flag_payload_tpl { 566 + template_content = fs::read_to_string(template_file)?; 567 + let mut env = Environment::new(); 568 + env.set_unknown_method_callback(unknown_method_callback); 569 + env.add_template("template", &template_content)?; 570 + payload_content_type = ContentType::Json; 571 + env 572 + } else { 573 + payload_content_type = ContentType::Form; 574 + Environment::empty() 575 ~ }; | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/fetchpost.rs:1397:9 | 1397 | / match resp_result { 1398 | | Ok(resp) => { 1399 | | // debug!("{resp:?}"); 1400 | | api_respheader.clone_from(resp.headers()); ... | 1473 | | }, 1474 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 1397 ~ if let Ok(resp) = resp_result { 1398 + // debug!("{resp:?}"); 1399 + api_respheader.clone_from(resp.headers()); 1400 + api_status = resp.status(); 1401 + api_value = resp.text().unwrap_or_default(); 1402 + 1403 + if api_status.is_client_error() || api_status.is_server_error() { 1404 + error_flag = true; 1405 + error!( 1406 + "HTTP error. url: {valid_url:?}, error: {:?}", 1407 + api_status.canonical_reason().unwrap_or("unknown error") 1408 + ); 1409 + 1410 + if flag_store_error { 1411 + final_value = format!( 1412 + "HTTP ERROR {} - {}", 1413 + api_status.as_str(), 1414 + api_status.canonical_reason().unwrap_or("unknown error") 1415 + ); 1416 + } else { 1417 + final_value = String::new(); 1418 + } 1419 + } else { 1420 + error_flag = false; 1421 + // apply jaq selector if provided 1422 + if let Some(selectors) = flag_jaq { 1423 + match process_jaq(&api_value, selectors) { 1424 + Ok(s) => { 1425 + final_value = s; 1426 + }, 1427 + Err(e) => { 1428 + error!( 1429 + "jaq error. json: {api_value:?}, selectors: {selectors:?}, \ 1430 + error: {e:?}" 1431 + ); 1432 + 1433 + if flag_store_error { 1434 + final_value = e.to_string(); 1435 + } else { 1436 + final_value = String::new(); 1437 + } 1438 + error_flag = true; 1439 + }, 1440 + } 1441 + } else { 1442 + // validate the JSON response 1443 + api_value_json_result = 1444 + serde_json::from_str::<serde_json::Value>(&api_value); 1445 + match api_value_json_result { 1446 + Ok(api_value_json) => { 1447 + if flag_pretty { 1448 + final_value = format!("{api_value_json:#}"); 1449 + } else { 1450 + // use serde_json CompactFormatter to minify the JSON 1451 + final_value = format!("{api_value_json}"); 1452 + } 1453 + }, 1454 + Err(e) => { 1455 + error!("json error. json: {api_value:?}, error: {e:?}"); 1456 + 1457 + if flag_store_error { 1458 + final_value = e.to_string(); 1459 + } else { 1460 + final_value = String::new(); 1461 + } 1462 + error_flag = true; 1463 + }, 1464 + } 1465 + } 1466 + } 1467 + } else { 1468 + error_flag = true; 1469 + api_respheader.clear(); 1470 + api_status = reqwest::StatusCode::BAD_REQUEST; 1471 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/luau.rs:2565:28 | 2565 | let prev_acc = match luau.globals().raw_get::<f64>(&*state_name) { | ____________________________^ 2566 | | Ok(prev) => prev, 2567 | | _ => { ... | 2586 | | }, 2587 | | }; | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 2565 ~ let prev_acc = if let Ok(prev) = luau.globals().raw_get::<f64>(&*state_name) { prev } else { 2566 + // Get initial value from optional argument or default to the first column value 2567 + let init_value = match init { 2568 + Some(init) => match init { 2569 + mlua::Value::Number(n) => n, 2570 + mlua::Value::Integer(i) => i as f64, 2571 + mlua::Value::String(s) => { 2572 + fast_float2::parse(s.as_bytes()).unwrap_or(0.0) 2573 + }, 2574 + _ => 0.0, 2575 + }, 2576 + _ => { 2577 + // By default, the first column value is used as the initial value 2578 + // unless the optional initial value is provided. 2579 + curr_value 2580 + }, 2581 + }; 2582 + luau.globals().raw_set(&*state_name, init_value)?; 2583 + init_value 2584 ~ }; | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/reverse.rs:53:5 | 53 | / match rconfig.indexed()? { 54 | | Some(mut idx_file) => { ... | 81 | | }, 82 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 53 ~ if let Some(mut idx_file) = rconfig.indexed()? { 54 + // we have an index, no need to check avail mem, 55 + // we're reading the file in reverse streaming 56 + rconfig.write_headers(&mut rdr, &mut wtr)?; 57 + let mut record = csv::ByteRecord::new(); 58 + let mut pos = idx_file.count().saturating_sub(1); 59 + 60 + while idx_file.seek(pos).is_ok() { 61 + idx_file.read_byte_record(&mut record)?; 62 + wtr.write_byte_record(&record)?; 63 + pos -= 1; 64 + } 65 + } else { 66 + // we don't have an index, we need to read the entire file into memory 67 + // we're loading the entire file into memory, we need to check avail mem 68 + if let Some(ref path) = rconfig.path { 69 + util::mem_file_check(path, false, args.flag_memcheck)?; 70 + } 71 + 72 + let mut all = rdr.byte_records().collect::<Result<Vec<_>, _>>()?; 73 + all.reverse(); 74 + 75 + rconfig.write_headers(&mut rdr, &mut wtr)?; 76 + for r in all { 77 + wtr.write_byte_record(&r)?; 78 + } 79 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/cmd/sample.rs:616:13 | 616 | / match rconfig.indexed()? { 617 | | Some(mut idx) => { 618 | | #[allow(clippy::cast_precision_loss)] 619 | | if sample_size < 1.0 { ... | 685 | | }, 686 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 616 ~ if let Some(mut idx) = rconfig.indexed()? { 617 + #[allow(clippy::cast_precision_loss)] 618 + if sample_size < 1.0 { 619 + sample_size *= idx.count() as f64; 620 + } 621 + 622 + let sample_count = sample_size as usize; 623 + let total_count = idx.count().try_into().unwrap(); 624 + 625 + match rng_kind { 626 + RngKind::Standard => { 627 + log::info!("doing standard INDEXED sampling..."); 628 + let mut rng = StandardRng::create(args.flag_seed); 629 + sample_indices(&mut rng, total_count, sample_count, |i| { 630 + idx.seek(i as u64)?; 631 + Ok(wtr.write_byte_record(&idx.byte_records().next().unwrap()?)?) 632 + })?; 633 + }, 634 + RngKind::Faster => { 635 + log::info!("doing --faster INDEXED sampling..."); 636 + let mut rng = FasterRng::create(args.flag_seed); 637 + sample_indices(&mut rng, total_count, sample_count, |i| { 638 + idx.seek(i as u64)?; 639 + Ok(wtr.write_byte_record(&idx.byte_records().next().unwrap()?)?) 640 + })?; 641 + }, 642 + RngKind::Cryptosecure => { 643 + log::info!("doing --cryptosecure INDEXED sampling..."); 644 + let mut rng = CryptoRng::create(args.flag_seed); 645 + sample_indices(&mut rng, total_count, sample_count, |i| { 646 + idx.seek(i as u64)?; 647 + Ok(wtr.write_byte_record(&idx.byte_records().next().unwrap()?)?) 648 + })?; 649 + }, 650 + } 651 + } else { 652 + // No sampling method is specified and no index is present 653 + // do reservoir sampling 654 + 655 + #[allow(clippy::cast_precision_loss)] 656 + let sample_size = if args.arg_sample_size < 1.0 { 657 + // Get rowcount from stats cache if available 658 + let (rowcount_stats, _, _) = 659 + check_stats_cache(&args, &SamplingMethod::Default)?; 660 + 661 + if let Some(rc) = rowcount_stats { 662 + (rc as f64 * args.arg_sample_size).round() as u64 663 + } else { 664 + match util::count_rows(&rconfig) { 665 + Ok(rc) => { 666 + // we don't have a stats cache, get the rowcount the "regular" 667 + // way 668 + (rc as f64 * args.arg_sample_size).round() as u64 669 + }, 670 + _ => { 671 + return fail!( 672 + "Cannot get rowcount. Percentage sampling requires a \ 673 + rowcount." 674 + ); 675 + }, 676 + } 677 + } 678 + } else { 679 + args.arg_sample_size as u64 680 + }; 681 + 682 + sample_reservoir(&mut rdr, &mut wtr, sample_size, args.flag_seed, &rng_kind)?; 683 + } | warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/util.rs:534:5 | 534 | / match conf.indexed().unwrap_or(None) { 535 | | Some(idx) => Ok(idx.count()), 536 | | _ => { ... | 556 | | }, 557 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 534 ~ if let Some(idx) = conf.indexed().unwrap_or(None) { Ok(idx.count()) } else { 535 + // index does not exist or is stale, 536 + let count_opt = 537 + ROW_COUNT.get_or_init(|| match conf.clone().skip_format_check(true).reader() { 538 + Ok(mut rdr) => { 539 + let mut count = 0_u64; 540 + let mut _record = csv::ByteRecord::new(); 541 + #[allow(clippy::used_underscore_binding)] 542 + while rdr.read_byte_record(&mut _record).unwrap_or_default() { 543 + count += 1; 544 + } 545 + Some(count) 546 + }, 547 + _ => None, 548 + }); 549 + 550 + match *count_opt { 551 + Some(count) => Ok(count), 552 + None => Err(CliError::Other("Unable to get row count".to_string())), 553 + } 554 + } | warning: unnecessary semicolon --> src/util.rs:1040:14 | 1040 | }; | ^ help: remove | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_semicolon = note: `-W clippy::unnecessary-semicolon` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unnecessary_semicolon)]`
warning: this `else { if .. }` block can be collapsed --> src/cmd/excel.rs:905:16 | 905 | } else { | ________________^ 906 | | if let Some(result) = sheets.worksheet_range_at(sheet_index) { 907 | | export_mode = ExportMode::Sheet; 908 | | result? ... | 913 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 905 ~ } else if let Some(result) = sheets.worksheet_range_at(sheet_index) { 906 + export_mode = ExportMode::Sheet; 907 + result? 908 + } else { 909 + export_mode = ExportMode::NothingToExport; 910 + Range::empty() 911 + }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.