From f5a682ccce103a102e9b5f8715df543749c6edbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Saparelli?= Date: Sun, 4 Sep 2022 23:00:33 +1200 Subject: [PATCH] Stop using borrows of reqwest::Client (#316) --- crates/lib/src/drivers/crates_io.rs | 2 +- crates/lib/src/fetchers/gh_crate_meta.rs | 2 +- crates/lib/src/fetchers/quickinstall.rs | 2 +- crates/lib/src/helpers/download.rs | 12 ++++++------ crates/lib/src/helpers/remote.rs | 2 +- crates/lib/src/ops/resolve.rs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/lib/src/drivers/crates_io.rs b/crates/lib/src/drivers/crates_io.rs index 4858f246f..21b1da26d 100644 --- a/crates/lib/src/drivers/crates_io.rs +++ b/crates/lib/src/drivers/crates_io.rs @@ -22,7 +22,7 @@ use visitor::ManifestVisitor; /// Fetch a crate Cargo.toml by name and version from crates.io pub async fn fetch_crate_cratesio( - client: &Client, + client: Client, crates_io_api_client: &AsyncClient, name: &str, version_req: &VersionReq, diff --git a/crates/lib/src/fetchers/gh_crate_meta.rs b/crates/lib/src/fetchers/gh_crate_meta.rs index 56dac9fa5..dea1877eb 100644 --- a/crates/lib/src/fetchers/gh_crate_meta.rs +++ b/crates/lib/src/fetchers/gh_crate_meta.rs @@ -145,7 +145,7 @@ impl super::Fetcher for GhCrateMeta { async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let (url, pkg_fmt) = self.resolution.get().unwrap(); // find() is called first debug!("Downloading package from: '{url}'"); - Download::new(&self.client, url.clone()) + Download::new(self.client.clone(), url.clone()) .and_extract(self.pkg_fmt(), dst) .await } diff --git a/crates/lib/src/fetchers/quickinstall.rs b/crates/lib/src/fetchers/quickinstall.rs index a2bf40128..e94795c71 100644 --- a/crates/lib/src/fetchers/quickinstall.rs +++ b/crates/lib/src/fetchers/quickinstall.rs @@ -49,7 +49,7 @@ impl super::Fetcher for QuickInstall { async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let url = self.package_url(); debug!("Downloading package from: '{url}'"); - Download::new(&self.client, Url::parse(&url)?) + Download::new(self.client.clone(), Url::parse(&url)?) .and_extract(self.pkg_fmt(), dst) .await } diff --git a/crates/lib/src/helpers/download.rs b/crates/lib/src/helpers/download.rs index 9fb6d8e50..4918e176f 100644 --- a/crates/lib/src/helpers/download.rs +++ b/crates/lib/src/helpers/download.rs @@ -18,15 +18,15 @@ mod extracter; mod stream_readable; #[derive(Debug)] -pub struct Download<'client, D: Digest = NoDigest> { - client: &'client Client, +pub struct Download { + client: Client, url: Url, _digest: PhantomData, _checksum: Vec, } -impl<'client> Download<'client> { - pub fn new(client: &'client Client, url: Url) -> Self { +impl Download { + pub fn new(client: Client, url: Url) -> Self { Self { client, url, @@ -82,8 +82,8 @@ impl<'client> Download<'client> { } } -impl<'client, D: Digest> Download<'client, D> { - pub fn new_with_checksum(client: &'client Client, url: Url, checksum: Vec) -> Self { +impl Download { + pub fn new_with_checksum(client: Client, url: Url, checksum: Vec) -> Self { Self { client, url, diff --git a/crates/lib/src/helpers/remote.rs b/crates/lib/src/helpers/remote.rs index e609015cc..ddfdce82a 100644 --- a/crates/lib/src/helpers/remote.rs +++ b/crates/lib/src/helpers/remote.rs @@ -56,7 +56,7 @@ pub async fn get_redirected_final_url(client: &Client, url: Url) -> Result Result>, BinstallError> { debug!("Downloading from: '{url}'"); diff --git a/crates/lib/src/ops/resolve.rs b/crates/lib/src/ops/resolve.rs index bcbaae6b0..97a553d45 100644 --- a/crates/lib/src/ops/resolve.rs +++ b/crates/lib/src/ops/resolve.rs @@ -133,7 +133,7 @@ async fn resolve_inner( Some(manifest_path) => load_manifest_path(manifest_path)?, None => { fetch_crate_cratesio( - &client, + client.clone(), &crates_io_api_client, &crate_name.name, &version_req,