diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9fea980 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.checkOnSave.command": "clippy" +} diff --git a/compressor_integration_tests/tests/compressor_config_tests.rs b/compressor_integration_tests/tests/compressor_config_tests.rs index f941781..dec7fc1 100644 --- a/compressor_integration_tests/tests/compressor_config_tests.rs +++ b/compressor_integration_tests/tests/compressor_config_tests.rs @@ -49,8 +49,8 @@ fn run_succeeds_without_crashing() { let verify = true; let config = Config::new( - db_url.clone(), - room_id.clone(), + db_url, + room_id, output_file, min_state_group, groups_to_compress, @@ -525,14 +525,14 @@ fn run_is_idempotent_when_run_on_whole_room() { .unwrap(); let config2 = Config::new( - db_url.clone(), - room_id.clone(), + db_url, + room_id, output_file2, min_state_group, groups_to_compress, min_saved_rows, max_state_group, - level_sizes.clone(), + level_sizes, transactions, graphs, commit_changes, diff --git a/compressor_integration_tests/tests/compressor_continue_run_tests.rs b/compressor_integration_tests/tests/compressor_continue_run_tests.rs index 0ae05db..0da1efe 100644 --- a/compressor_integration_tests/tests/compressor_continue_run_tests.rs +++ b/compressor_integration_tests/tests/compressor_continue_run_tests.rs @@ -56,7 +56,7 @@ fn continue_run_called_twice_same_as_run() { let start = Some(6); let chunk_size = 7; - let level_info = chunk_stats_1.new_level_info.clone(); + let level_info = chunk_stats_1.new_level_info; // Run the compressor with those settings let chunk_stats_2 = continue_run(start, chunk_size, &db_url, &room_id, &level_info).unwrap(); diff --git a/src/compressor.rs b/src/compressor.rs index ea74e01..6559ef0 100644 --- a/src/compressor.rs +++ b/src/compressor.rs @@ -181,12 +181,11 @@ impl<'a> Compressor<'a> { panic!("Can only call `create_new_tree` once"); } - let pb: ProgressBar; - if cfg!(feature = "no-progress-bars") { - pb = ProgressBar::hidden(); + let pb: ProgressBar = if cfg!(feature = "no-progress-bars") { + ProgressBar::hidden() } else { - pb = ProgressBar::new(self.original_state_map.len() as u64); - } + ProgressBar::new(self.original_state_map.len() as u64) + }; pb.set_style( ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"), ); diff --git a/src/compressor/compressor_tests.rs b/src/compressor/compressor_tests.rs index de64189..2230c3c 100644 --- a/src/compressor/compressor_tests.rs +++ b/src/compressor/compressor_tests.rs @@ -93,14 +93,7 @@ fn create_new_tree_does_nothing_if_already_compressed() { for i in 0i64..=13i64 { // edge from map - let pred_group = initial_edges.get(&i); - - // Need Option not Option<&i64> - let prev; - match pred_group { - Some(i) => prev = Some(*i), - None => prev = None, - } + let prev = initial_edges.get(&i).copied(); // insert that edge into the initial map initial.insert( diff --git a/src/compressor/level_tests.rs b/src/compressor/level_tests.rs index b058b81..2162037 100644 --- a/src/compressor/level_tests.rs +++ b/src/compressor/level_tests.rs @@ -54,7 +54,7 @@ fn get_head_returns_head() { #[test] fn has_space_returns_true_if_empty() { let l = Level::new(15); - assert_eq!(l.has_space(), true); + assert!(l.has_space()); } #[test] @@ -65,7 +65,7 @@ fn has_space_returns_true_if_part_full() { l.update(1, true); l.update(143, true); l.update(15, true); - assert_eq!(l.has_space(), true); + assert!(l.has_space()); } #[test] @@ -76,5 +76,5 @@ fn has_space_returns_false_if_full() { l.update(3, true); l.update(4, true); l.update(5, true); - assert_eq!(l.has_space(), false); + assert!(!l.has_space()); } diff --git a/src/compressor/stats_tests.rs b/src/compressor/stats_tests.rs index 4bec720..ec6feba 100644 --- a/src/compressor/stats_tests.rs +++ b/src/compressor/stats_tests.rs @@ -142,14 +142,7 @@ fn stats_correct_if_no_changes() { for i in 0i64..=13i64 { // edge from map - let pred_group = initial_edges.get(&i); - - // Need Option not Option<&i64> - let prev; - match pred_group { - Some(i) => prev = Some(*i), - None => prev = None, - } + let prev = initial_edges.get(&i).copied(); // insert that edge into the initial map initial.insert( diff --git a/src/database.rs b/src/database.rs index 3982be8..17b736c 100644 --- a/src/database.rs +++ b/src/database.rs @@ -372,12 +372,11 @@ fn get_initial_data_from_db( // Copy the data from the database into a map let mut state_group_map: BTreeMap = BTreeMap::new(); - let pb: ProgressBar; - if cfg!(feature = "no-progress-bars") { - pb = ProgressBar::hidden(); + let pb: ProgressBar = if cfg!(feature = "no-progress-bars") { + ProgressBar::hidden() } else { - pb = ProgressBar::new_spinner(); - } + ProgressBar::new_spinner() + }; pb.set_style( ProgressStyle::default_spinner().template("{spinner} [{elapsed}] {pos} rows retrieved"), ); @@ -537,12 +536,11 @@ pub fn send_changes_to_db( debug!("Writing changes..."); // setup the progress bar - let pb: ProgressBar; - if cfg!(feature = "no-progress-bars") { - pb = ProgressBar::hidden(); + let pb: ProgressBar = if cfg!(feature = "no-progress-bars") { + ProgressBar::hidden() } else { - pb = ProgressBar::new(old_map.len() as u64); - } + ProgressBar::new(old_map.len() as u64) + }; pb.set_style( ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"), ); diff --git a/src/lib.rs b/src/lib.rs index af2a8db..e87a749 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -507,12 +507,11 @@ fn output_sql( info!("Writing changes..."); - let pb: ProgressBar; - if cfg!(feature = "no-progress-bars") { - pb = ProgressBar::hidden(); + let pb: ProgressBar = if cfg!(feature = "no-progress-bars") { + ProgressBar::hidden() } else { - pb = ProgressBar::new(old_map.len() as u64); - } + ProgressBar::new(old_map.len() as u64) + }; pb.set_style( ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"), ); @@ -622,12 +621,11 @@ fn check_that_maps_match( ) { info!("Checking that state maps match..."); - let pb: ProgressBar; - if cfg!(feature = "no-progress-bars") { - pb = ProgressBar::hidden(); + let pb: ProgressBar = if cfg!(feature = "no-progress-bars") { + ProgressBar::hidden() } else { - pb = ProgressBar::new(old_map.len() as u64); - } + ProgressBar::new(old_map.len() as u64) + }; pb.set_style( ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"), ); @@ -975,7 +973,6 @@ mod lib_tests { #[test] fn check_that_maps_match_returns_if_both_empty() { check_that_maps_match(&BTreeMap::new(), &BTreeMap::new()); - assert!(true); } #[test] @@ -1008,7 +1005,6 @@ mod lib_tests { } check_that_maps_match(&old_map, &BTreeMap::new()); - assert!(true); } #[test] @@ -1044,7 +1040,6 @@ mod lib_tests { } check_that_maps_match(&BTreeMap::new(), &new_map); - assert!(true); } #[test] @@ -1076,7 +1071,6 @@ mod lib_tests { } check_that_maps_match(&BTreeMap::new(), &old_map.clone()); - assert!(true); } #[test] @@ -1139,7 +1133,6 @@ mod lib_tests { } check_that_maps_match(&old_map, &new_map); - assert!(true); } #[test] @@ -1221,7 +1214,6 @@ mod lib_tests { ); check_that_maps_match(&old_map, &new_map); - assert!(true); } //TODO: tests for correct SQL code produced by output_sql @@ -1311,7 +1303,7 @@ mod pyo3_tests { .unwrap(); assert_eq!(config.db_url, db_url); - assert!(!config.output_file.is_none()); + assert!(config.output_file.is_some()); assert_eq!(config.room_id, room_id); assert_eq!(config.min_state_group, Some(3225)); assert_eq!(config.groups_to_compress, Some(970));