commit:     162c0863a6742cb488632ee4aa2c4c427629a2cf
Author:     Leonardo Neumann <leonardo <AT> neumann <DOT> dev <DOT> br>
AuthorDate: Sat Aug 14 20:34:49 2021 +0000
Commit:     Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
CommitDate: Thu Aug 26 07:40:36 2021 +0000
URL:        https://gitweb.gentoo.org/proj/cargo-ebuild.git/commit/?id=162c0863

Use path references instead of owned counterparts

PathBuf is not necessary because the paths are not being modified. Since
generic monomorphization such as AsRef<Path> is a common source of code
bloat, I decided to use &Path instead.

Signed-off-by: Leonardo Neumann <leonardo <AT> neumann.dev.br>
Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>

 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<PathBuf>) -> Result<EbuildConfig> 
{
+pub fn gen_ebuild_data(manifest_path: Option<&Path>) -> Result<EbuildConfig> {
     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<PathBuf>) -> 
Result<EbuildConfig> {
 
 pub fn write_ebuild(
     ebuild_data: EbuildConfig,
-    ebuild_path: impl AsRef<Path>,
-    template_path: Option<impl AsRef<Path>>,
+    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);
 

Reply via email to