From 668e5df60e3df83c05ef0f3d1131edaa290d0208 Mon Sep 17 00:00:00 2001 From: Jake Runzer Date: Wed, 4 Dec 2024 15:03:54 -0500 Subject: [PATCH] update rust and apply lint fixes (#1236) --- src/nixpacks/nix/mod.rs | 9 ++++++--- src/nixpacks/plan/generator.rs | 2 +- src/nixpacks/plan/phase.rs | 24 ++++++++++++------------ src/providers/node/mod.rs | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/nixpacks/nix/mod.rs b/src/nixpacks/nix/mod.rs index 1cebca81f..4ca919109 100644 --- a/src/nixpacks/nix/mod.rs +++ b/src/nixpacks/nix/mod.rs @@ -70,7 +70,10 @@ pub fn create_nix_expressions_for_phases(phases: &Phases) -> BTreeMap Vec { .filter(|p| p.uses_nix()) .map(|p| p.nixpkgs_archive.clone()) .collect::>(); - archives.iter().map(nix_file_name).collect() + archives.iter().map(|a| nix_file_name(a.as_ref())).collect() } /// Returns all the Nix expression files used to install Nix dependencies for each phase. @@ -101,7 +104,7 @@ pub fn setup_files_for_phases(phases: &Phases) -> Vec { } /// Generates the filename for each Nix expression file. -fn nix_file_name(archive: &Option) -> String { +fn nix_file_name(archive: Option<&String>) -> String { match archive { Some(archive) => format!("nixpkgs-{archive}.nix"), None => "nixpkgs.nix".to_string(), diff --git a/src/nixpacks/plan/generator.rs b/src/nixpacks/plan/generator.rs index 996439907..98abe7df2 100644 --- a/src/nixpacks/plan/generator.rs +++ b/src/nixpacks/plan/generator.rs @@ -31,7 +31,7 @@ pub struct NixpacksBuildPlanGenerator<'a> { } /// NixpacksBuildPlanGenerators produce build plans using the options and providers they contain. -impl<'a> PlanGenerator for NixpacksBuildPlanGenerator<'a> { +impl PlanGenerator for NixpacksBuildPlanGenerator<'_> { fn generate_plan(&mut self, app: &App, environment: &Environment) -> Result<(BuildPlan, App)> { // If the provider defines a build plan in the new format, use that let plan = self.get_build_plan(app, environment)?; diff --git a/src/nixpacks/plan/phase.rs b/src/nixpacks/plan/phase.rs index 2872b5d8c..d64113d41 100644 --- a/src/nixpacks/plan/phase.rs +++ b/src/nixpacks/plan/phase.rs @@ -218,15 +218,15 @@ impl Phase { } } - self.cmds = pin_option_vec(&self.cmds); - self.depends_on = pin_option_vec(&self.depends_on); - self.nix_pkgs = pin_option_vec(&self.nix_pkgs); - self.nix_libs = pin_option_vec(&self.nix_libs); - self.apt_pkgs = pin_option_vec(&self.apt_pkgs); - self.nix_overlays = pin_option_vec(&self.nix_overlays); - self.only_include_files = pin_option_vec(&self.only_include_files); - self.cache_directories = pin_option_vec(&self.cache_directories); - self.paths = pin_option_vec(&self.paths); + self.cmds = pin_option_vec(self.cmds.as_ref()); + self.depends_on = pin_option_vec(self.depends_on.as_ref()); + self.nix_pkgs = pin_option_vec(self.nix_pkgs.as_ref()); + self.nix_libs = pin_option_vec(self.nix_libs.as_ref()); + self.apt_pkgs = pin_option_vec(self.apt_pkgs.as_ref()); + self.nix_overlays = pin_option_vec(self.nix_overlays.as_ref()); + self.only_include_files = pin_option_vec(self.only_include_files.as_ref()); + self.cache_directories = pin_option_vec(self.cache_directories.as_ref()); + self.paths = pin_option_vec(self.paths.as_ref()); } } @@ -263,16 +263,16 @@ impl StartPhase { /// Store the list of files to include in this phase for later reproducibility. pub fn pin(&mut self) { - self.only_include_files = pin_option_vec(&self.only_include_files); + self.only_include_files = pin_option_vec(self.only_include_files.as_ref()); } } /// Store the list of options for this phase for later reproducibility. -fn pin_option_vec(vec: &Option>) -> Option> { +fn pin_option_vec(vec: Option<&Vec>) -> Option> { if let Some(vec) = vec { Some(remove_autos_from_vec(vec.clone())) } else { - vec.clone() + vec.cloned() } } diff --git a/src/providers/node/mod.rs b/src/providers/node/mod.rs index d86284853..ff457b5bd 100644 --- a/src/providers/node/mod.rs +++ b/src/providers/node/mod.rs @@ -353,7 +353,7 @@ impl NodeProvider { } let node_pkg = parse_node_version_into_pkg(&node_version); - return Ok(Pkg::new(node_pkg.as_str())); + Ok(Pkg::new(node_pkg.as_str())) } pub fn get_package_manager(app: &App) -> String {