mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Better return type for download_index
(#5086)
This commit is contained in:
parent
3ec5d442d7
commit
ae7787c820
@ -128,19 +128,21 @@ impl PackageStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Download the package index. The result of this is cached for efficiency.
|
/// Download the package index. The result of this is cached for efficiency.
|
||||||
pub fn download_index(&self) -> StrResult<&Vec<PackageInfo>> {
|
pub fn download_index(&self) -> StrResult<&[PackageInfo]> {
|
||||||
self.index.get_or_try_init(|| {
|
self.index
|
||||||
|
.get_or_try_init(|| {
|
||||||
let url = format!("{DEFAULT_REGISTRY}/preview/index.json");
|
let url = format!("{DEFAULT_REGISTRY}/preview/index.json");
|
||||||
match self.downloader.download(&url) {
|
match self.downloader.download(&url) {
|
||||||
Ok(response) => response
|
Ok(response) => response.into_json().map_err(|err| {
|
||||||
.into_json()
|
eco_format!("failed to parse package index: {err}")
|
||||||
.map_err(|err| eco_format!("failed to parse package index: {err}")),
|
}),
|
||||||
Err(ureq::Error::Status(404, _)) => {
|
Err(ureq::Error::Status(404, _)) => {
|
||||||
bail!("failed to fetch package index (not found)")
|
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.
|
/// Download a package over the network.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user