diff --git a/rust/fastsim-cli/tests/integration-tests.rs b/rust/fastsim-cli/tests/integration-tests.rs index 30675062..6e7b5a53 100644 --- a/rust/fastsim-cli/tests/integration-tests.rs +++ b/rust/fastsim-cli/tests/integration-tests.rs @@ -32,7 +32,7 @@ fn test_that_cli_app_produces_result() { #[test] fn test_that_adopt_hd_option_works_as_expected() { - let expected_results = vec![ + let expected_results = [ ("adoptstring.json", "0.245"), // 0.245 kWh/mile ("adoptstring2.json", "7.906"), // 7.906 mpgge ("adoptstring3.json", "6.882"), // 6.882 mpgge diff --git a/rust/fastsim-core/src/cycle.rs b/rust/fastsim-core/src/cycle.rs index ab8175b3..821715e5 100644 --- a/rust/fastsim-core/src/cycle.rs +++ b/rust/fastsim-core/src/cycle.rs @@ -497,22 +497,22 @@ impl RustCycleCache { #[staticmethod] pub fn from_dict(dict: &PyDict) -> anyhow::Result { - let time_s = Array::from_vec(PyAny::get_item(&dict, "time_s")?.extract()?); + let time_s = Array::from_vec(PyAny::get_item(dict, "time_s")?.extract()?); let cyc_len = time_s.len(); Ok(Self { time_s, - mps: Array::from_vec(PyAny::get_item(&dict, "mps")?.extract()?), - grade: if let Ok(value) = PyAny::get_item(&dict, "grade") { + mps: Array::from_vec(PyAny::get_item(dict, "mps")?.extract()?), + grade: if let Ok(value) = PyAny::get_item(dict, "grade") { Array::from_vec(value.extract()?) } else { Array::default(cyc_len) }, - road_type: if let Ok(value) = PyAny::get_item(&dict, "road_type") { + road_type: if let Ok(value) = PyAny::get_item(dict, "road_type") { Array::from_vec(value.extract()?) } else { Array::default(cyc_len) }, - name: PyAny::get_item(&dict, "name").and_then(String::extract).unwrap_or_default(), + name: PyAny::get_item(dict, "name").and_then(String::extract).unwrap_or_default(), orphaned: false, }) } @@ -737,13 +737,13 @@ impl TryFrom>> for RustCycle { } } -impl Into>> for RustCycle { - fn into(self) -> HashMap> { +impl From for HashMap> { + fn from(cyc: RustCycle) -> Self { HashMap::from([ - ("time_s".into(), self.time_s.to_vec()), - ("mps".into(), self.mps.to_vec()), - ("grade".into(), self.grade.to_vec()), - ("road_type".into(), self.road_type.to_vec()), + ("time_s".into(), cyc.time_s.to_vec()), + ("mps".into(), cyc.mps.to_vec()), + ("grade".into(), cyc.grade.to_vec()), + ("road_type".into(), cyc.road_type.to_vec()), ]) } } diff --git a/rust/fastsim-core/src/utils.rs b/rust/fastsim-core/src/utils.rs index af3b376f..c69f95da 100644 --- a/rust/fastsim-core/src/utils.rs +++ b/rust/fastsim-core/src/utils.rs @@ -431,12 +431,11 @@ pub fn multilinear(point: &[f64], grid: &[Vec], values: &ArrayD) -> an Slice::from(lower..=lower + 1) }) .to_owned(); - let mut index_permutations = get_index_permutations(&interp_vals.shape()); + let mut index_permutations = get_index_permutations(interp_vals.shape()); // This loop interpolates in each dimension sequentially // each outer loop iteration the dimensionality reduces by 1 // `interp_vals` ends up as a 0-dimensional array containing only the final interpolated value - for dim in 0..n { - let diff = interp_diffs[dim]; + for (dim, diff) in interp_diffs.iter().enumerate() { let next_dim = n - 1 - dim; let next_shape = vec![2; next_dim]; // Indeces used for saving results of this dimensions interpolation results diff --git a/rust/fastsim-core/src/vehicle_utils.rs b/rust/fastsim-core/src/vehicle_utils.rs index fe8e7887..a08ae471 100644 --- a/rust/fastsim-core/src/vehicle_utils.rs +++ b/rust/fastsim-core/src/vehicle_utils.rs @@ -1330,7 +1330,7 @@ fn read_fuelecon_gov_emissions_to_hashmap( if let Some(item) = ok_result { if let Some(id_str) = item.get("id") { if let Ok(id) = str::parse::(id_str) { - output.entry(id).or_insert_with(Vec::new); + output.entry(id).or_default(); if let Some(ers) = output.get_mut(&id) { let emiss = EmissionsInfoFE { efid: item.get("efid").unwrap().clone(), @@ -1463,7 +1463,7 @@ pub fn get_fastsim_data_dir() -> Option { pub fn extract_zip(filepath: &Path, dest_dir: &Path) -> Result<(), anyhow::Error> { let f = File::open(filepath)?; let mut zip = zip::ZipArchive::new(f)?; - zip.extract(&dest_dir)?; + zip.extract(dest_dir)?; Ok(()) } @@ -1489,7 +1489,7 @@ pub fn download_file_from_url(url: &str, file_path: &Path) -> Result<(), anyhow: return Err(anyhow!("No data available from {url}")); } { - let mut file = match File::create(&file_path) { + let mut file = match File::create(file_path) { Err(why) => { return Err(anyhow!( "couldn't open {}: {}",