From ae7787c8202cabf9d01c2d17bbc93c5d372dd842 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 1 Oct 2024 15:35:02 +0200 Subject: [PATCH] Better return type for `download_index` (#5086) --- crates/typst-kit/src/package.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/typst-kit/src/package.rs b/crates/typst-kit/src/package.rs index c5c470db8..839780106 100644 --- a/crates/typst-kit/src/package.rs +++ b/crates/typst-kit/src/package.rs @@ -128,19 +128,21 @@ impl PackageStorage { } /// Download the package index. The result of this is cached for efficiency. - pub fn download_index(&self) -> StrResult<&Vec> { - self.index.get_or_try_init(|| { - let url = format!("{DEFAULT_REGISTRY}/preview/index.json"); - match self.downloader.download(&url) { - Ok(response) => response - .into_json() - .map_err(|err| eco_format!("failed to parse package index: {err}")), - Err(ureq::Error::Status(404, _)) => { - bail!("failed to fetch package index (not found)") + pub fn download_index(&self) -> StrResult<&[PackageInfo]> { + self.index + .get_or_try_init(|| { + let url = format!("{DEFAULT_REGISTRY}/preview/index.json"); + match self.downloader.download(&url) { + Ok(response) => response.into_json().map_err(|err| { + eco_format!("failed to parse package index: {err}") + }), + Err(ureq::Error::Status(404, _)) => { + bail!("failed to fetch package index (not found)") + } + Err(err) => bail!("failed to fetch package index ({err})"), } - Err(err) => bail!("failed to fetch package index ({err})"), - } - }) + }) + .map(AsRef::as_ref) } /// Download a package over the network.