diff options
author | Leonardo Neumann <leonardo@neumann.dev.br> | 2021-08-14 17:34:49 -0300 |
---|---|---|
committer | Georgy Yakovlev <gyakovlev@gentoo.org> | 2021-08-26 00:40:36 -0700 |
commit | 162c0863a6742cb488632ee4aa2c4c427629a2cf (patch) | |
tree | 38b74e3f6cd5f5b4d3376d14911bf33a992012c6 | |
parent | Remove cargo-lock dependency (diff) | |
download | cargo-ebuild-162c0863a6742cb488632ee4aa2c4c427629a2cf.tar.gz cargo-ebuild-162c0863a6742cb488632ee4aa2c4c427629a2cf.tar.bz2 cargo-ebuild-162c0863a6742cb488632ee4aa2c4c427629a2cf.zip |
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@neumann.dev.br>
Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 4 |
2 files changed, 10 insertions, 10 deletions
@@ -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); |