From 162c0863a6742cb488632ee4aa2c4c427629a2cf Mon Sep 17 00:00:00 2001 From: Leonardo Neumann Date: Sat, 14 Aug 2021 17:34:49 -0300 Subject: Use path references instead of owned counterparts PathBuf is not necessary because the paths are not being modified. Since generic monomorphization such as AsRef is a common source of code bloat, I decided to use &Path instead. Signed-off-by: Leonardo Neumann Signed-off-by: Georgy Yakovlev --- src/lib.rs | 16 ++++++++-------- src/main.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 29fd0c2..6b2d2d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,17 +16,17 @@ use cargo_metadata::CargoOpt; use cargo_metadata::MetadataCommand; use std::collections::BTreeSet; use std::fs::OpenOptions; -use std::path::{Path, PathBuf}; +use std::path::Path; use license::{normalize_license, split_spdx_license}; use metadata::EbuildConfig; -pub fn gen_ebuild_data(manifest_path: Option) -> Result { +pub fn gen_ebuild_data(manifest_path: Option<&Path>) -> Result { let mut cmd = MetadataCommand::new(); cmd.features(CargoOpt::AllFeatures); - if let Some(path) = manifest_path.as_ref() { + if let Some(path) = manifest_path { cmd.manifest_path(path); } @@ -89,18 +89,18 @@ pub fn gen_ebuild_data(manifest_path: Option) -> Result { pub fn write_ebuild( ebuild_data: EbuildConfig, - ebuild_path: impl AsRef, - template_path: Option>, + ebuild_path: &Path, + template_path: Option<&Path>, ) -> Result<()> { // Open the file where we'll write the ebuild let mut file = OpenOptions::new() .write(true) .create(true) .truncate(true) - .open(&ebuild_path) + .open(ebuild_path) .context(format!( "Unable to create {}", - ebuild_path.as_ref().display() + ebuild_path.display() ))?; let mut tera = tera::Tera::default(); @@ -119,6 +119,6 @@ pub fn write_ebuild( tera.render_to("ebuild.tera", &context, &mut file) .context(format!( "Failed to write to {}", - ebuild_path.as_ref().display() + ebuild_path.display() )) } diff --git a/src/main.rs b/src/main.rs index fe8881c..12dd0e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,11 +45,11 @@ fn main() -> Result<()> { let Opt::Ebuild(opt) = Opt::from_args(); // compute the data from the package that the build needs - let ebuild_data = gen_ebuild_data(opt.manifest_path)?; + let ebuild_data = gen_ebuild_data(opt.manifest_path.as_deref())?; let ebuild_path = format!("{}-{}.ebuild", ebuild_data.name, ebuild_data.version); - write_ebuild(ebuild_data, &ebuild_path, opt.template_path.as_ref())?; + write_ebuild(ebuild_data, ebuild_path.as_ref(), opt.template_path.as_deref())?; println!("Wrote: {}", ebuild_path); -- cgit v1.2.3-65-gdbad