diff --git a/src/cosmic/cosm.rs b/src/cosmic/cosm.rs index 9024f4cd..958c19aa 100644 --- a/src/cosmic/cosm.rs +++ b/src/cosmic/cosm.rs @@ -77,7 +77,7 @@ impl FrameTree { /// Seek an ephemeris from its celestial name (e.g. Earth Moon Barycenter) fn frame_seek_by_name( name: &str, - cur_path: &mut [usize], + cur_path: &[usize], f: &FrameTree, ) -> Result, NyxError> { if f.name == name { @@ -91,7 +91,7 @@ impl FrameTree { for (cno, child) in f.children.iter().enumerate() { let mut this_path = cur_path.to_owned(); this_path.push(cno); - let child_attempt = Self::frame_seek_by_name(name, &mut this_path, child); + let child_attempt = Self::frame_seek_by_name(name, &this_path, child); if let Ok(found_path) = child_attempt { return Ok(found_path); } @@ -230,15 +230,15 @@ impl Cosm { // Return an empty vector (but OK because we're asking for the root) Ok(Vec::new()) } else { - let mut path = Vec::new(); - Self::frame_find_path(name, &mut path, &self.frame_root) + let path = Vec::new(); + Self::frame_find_path(name, &path, &self.frame_root) } } /// Seek a frame from its orientation name fn frame_find_path( frame_name: &str, - cur_path: &mut [usize], + cur_path: &[usize], f: &FrameTree, ) -> Result, NyxError> { if f.name == frame_name { @@ -250,8 +250,8 @@ impl Cosm { )) } else { for child in &f.children { - let mut this_path = cur_path.to_owned(); - let child_attempt = Self::frame_find_path(frame_name, &mut this_path, child); + let this_path = cur_path.to_owned(); + let child_attempt = Self::frame_find_path(frame_name, &this_path, child); if let Ok(found_path) = child_attempt { return Ok(found_path); } @@ -565,10 +565,10 @@ impl Cosm { // Return an empty vector (but OK because we're asking for the root) Ok(self.frame_root.frame) } else { - let mut path = Vec::new(); + let path = Vec::new(); Ok(self.frame_from_frame_path(&FrameTree::frame_seek_by_name( &name, - &mut path, + &path, &self.frame_root, )?)) } diff --git a/src/cosmic/mod.rs b/src/cosmic/mod.rs index d9864c65..4be157fd 100644 --- a/src/cosmic/mod.rs +++ b/src/cosmic/mod.rs @@ -25,7 +25,7 @@ use crate::linalg::{DefaultAllocator, DimName, OMatrix, OVector}; use crate::md::StateParameter; use crate::time::{Duration, Epoch, Unit}; use hifitime::SECONDS_PER_DAY; -use std::fmt; +use std::fmt::{self, Write}; use std::fs::File; use std::io::Read; #[cfg(not(target_arch = "wasm32"))] @@ -207,7 +207,10 @@ impl Xb { } for pos in path { if root.children.get(*pos).is_none() { - let hpath: String = path.iter().map(|p| format!("{p}")).collect::(); + let hpath = path.iter().fold(String::new(), |mut output, p| { + let _ = write!(output, "{p}"); + output + }); return Err(NyxError::ObjectNotFound(hpath, self.ephemeris_get_names())); } } @@ -231,7 +234,7 @@ impl Xb { /// Seek an ephemeris from its celestial name (e.g. Earth Moon Barycenter) fn ephemeris_seek_by_name( name: &str, - cur_path: &mut [usize], + cur_path: &[usize], e: &Ephemeris, ) -> Result, NyxError> { if e.name == name { @@ -245,7 +248,7 @@ impl Xb { for (cno, child) in e.children.iter().enumerate() { let mut this_path = cur_path.to_owned(); this_path.push(cno); - let child_attempt = Self::ephemeris_seek_by_name(name, &mut this_path, child); + let child_attempt = Self::ephemeris_seek_by_name(name, &this_path, child); if let Ok(found_path) = child_attempt { return Ok(found_path); } @@ -270,8 +273,8 @@ impl Xb { // Return an empty vector (but OK because we're asking for the root) Ok(Vec::new()) } else { - let mut path = Vec::new(); - Self::ephemeris_seek_by_name(&name, &mut path, root) + let path = Vec::new(); + Self::ephemeris_seek_by_name(&name, &path, root) } } } diff --git a/src/dynamics/spacecraft.rs b/src/dynamics/spacecraft.rs index e1206330..6b2ddcfd 100644 --- a/src/dynamics/spacecraft.rs +++ b/src/dynamics/spacecraft.rs @@ -30,7 +30,7 @@ pub use crate::md::prelude::SolarPressure; use crate::md::prelude::{Harmonics, PointMasses}; use crate::State; -use std::fmt; +use std::fmt::{self, Write}; use std::sync::Arc; use crate::cosmic::Cosm; @@ -243,7 +243,12 @@ impl fmt::Display for SpacecraftDynamics { let force_models: String = if self.force_models.is_empty() { "No force models;".to_string() } else { - self.force_models.iter().map(|x| format!("{x}; ")).collect() + self.force_models + .iter() + .fold(String::new(), |mut output, x| { + let _ = write!(output, "{x}; "); + output + }) }; write!( f, diff --git a/src/md/trajectory/orbit_traj.rs b/src/md/trajectory/orbit_traj.rs index b18d135d..08dab323 100644 --- a/src/md/trajectory/orbit_traj.rs +++ b/src/md/trajectory/orbit_traj.rs @@ -238,7 +238,7 @@ impl Traj { // Grab the path here before we move stuff. let path_buf = cfg.actual_path(path); - let metadata = cfg.metadata.unwrap_or(HashMap::new()); + let metadata = cfg.metadata.unwrap_or_default(); let file = File::create(&path_buf) .map_err(|e| NyxError::CCSDS(format!("File creation error: {e}")))?;