summaryrefslogtreecommitdiff
path: root/crates/typst-kit/src/package.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-01 15:35:02 +0200
committerGitHub <noreply@github.com>2024-10-01 13:35:02 +0000
commitae7787c8202cabf9d01c2d17bbc93c5d372dd842 (patch)
tree91f71ffbf966ff3ce1348e60484f762909a54576 /crates/typst-kit/src/package.rs
parent3ec5d442d7be4700aa02d015420ddd5cefa78b95 (diff)
Better return type for `download_index` (#5086)
Diffstat (limited to 'crates/typst-kit/src/package.rs')
-rw-r--r--crates/typst-kit/src/package.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/crates/typst-kit/src/package.rs b/crates/typst-kit/src/package.rs
index c5c470db..83978010 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<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)")
+ 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.