1use std::{fmt::Debug, sync::Arc};
2
3use tinymist_std::ImmutPath;
4use typst::diag::FileResult;
5
6use crate::{path_mapper::RootResolver, AccessModel, Bytes, FileId, PathAccessModel};
7
8#[derive(Clone)]
10pub struct ResolveAccessModel<M> {
11 pub resolver: Arc<dyn RootResolver + Send + Sync>,
13 pub inner: M,
15}
16
17impl<M> Debug for ResolveAccessModel<M> {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 f.debug_struct("ResolveAccessModel").finish()
20 }
21}
22
23impl<M: PathAccessModel> AccessModel for ResolveAccessModel<M> {
24 #[inline]
25 fn reset(&mut self) {
26 self.inner.reset();
27 }
28
29 fn content(&self, fid: FileId) -> (Option<ImmutPath>, FileResult<Bytes>) {
30 let resolved = Ok(()).and_then(|_| self.resolver.path_for_id(fid)?.to_err());
31
32 match resolved {
33 Ok(path) => (Some(path.as_path().into()), self.inner.content(&path)),
34 Err(e) => (None, Err(e)),
35 }
36 }
37}