tinymist_world/package/
mod.rs

1//! The package registry of the world.
2
3use std::sync::Arc;
4
5use tinymist_std::ImmutPath;
6use typst::diag::FileResult;
7
8pub use tinymist_package::*;
9
10/// A path mapper for the package registry.
11pub struct RegistryPathMapper<T> {
12    /// The package registry.
13    pub registry: Arc<T>,
14}
15
16impl<T> RegistryPathMapper<T> {
17    /// Creates a new path mapper for the package registry.
18    pub fn new(registry: Arc<T>) -> Self {
19        Self { registry }
20    }
21}
22
23impl<T: PackageRegistry> tinymist_vfs::RootResolver for RegistryPathMapper<T> {
24    fn resolve_package_root(&self, pkg: &PackageSpec) -> FileResult<ImmutPath> {
25        Ok(self.registry.resolve(pkg)?)
26    }
27}