From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3D86D1580BA for ; Thu, 26 Aug 2021 07:51:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 49C70E08FF; Thu, 26 Aug 2021 07:51:44 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2ECE9E08FF for ; Thu, 26 Aug 2021 07:51:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 302B6342BF2 for ; Thu, 26 Aug 2021 07:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1869A7DE for ; Thu, 26 Aug 2021 07:51:41 +0000 (UTC) From: "Georgy Yakovlev" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Georgy Yakovlev" Message-ID: <1629963636.162c0863a6742cb488632ee4aa2c4c427629a2cf.gyakovlev@gentoo> Subject: [gentoo-commits] proj/cargo-ebuild:master commit in: src/ X-VCS-Repository: proj/cargo-ebuild X-VCS-Files: src/lib.rs src/main.rs X-VCS-Directories: src/ X-VCS-Committer: gyakovlev X-VCS-Committer-Name: Georgy Yakovlev X-VCS-Revision: 162c0863a6742cb488632ee4aa2c4c427629a2cf X-VCS-Branch: master Date: Thu, 26 Aug 2021 07:51:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: e09da22e-43cc-44a6-a76a-b0b41866b432 X-Archives-Hash: 7f6a69290d64a0f483e9300d259256db commit: 162c0863a6742cb488632ee4aa2c4c427629a2cf Author: Leonardo Neumann neumann dev br> AuthorDate: Sat Aug 14 20:34:49 2021 +0000 Commit: Georgy Yakovlev gentoo 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 is a common source of code bloat, I decided to use &Path instead. Signed-off-by: Leonardo Neumann neumann.dev.br> Signed-off-by: Georgy Yakovlev 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) -> 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);