| 225 | impl Cache<PathBuf> for FileTreeCache<'_> { |
| 226 | type Storage = String; |
| 227 | fn fetch(&mut self, id: &PathBuf) -> Result<&Source<Self::Storage>, impl fmt::Debug> { |
| 228 | let file_contents = match self.file_tree.sources.get(id) { |
| 229 | Some(v) => v, |
| 230 | None => return Err(format!("Unknown file `{id:?}`")), |
| 231 | }; |
| 232 | |
| 233 | Ok(self |
| 234 | .cache |
| 235 | .entry(id.clone()) |
| 236 | .or_insert_with(|| Source::from(file_contents.to_string()))) |
| 237 | } |
| 238 | |
| 239 | fn display<'b>(&self, id: &'b PathBuf) -> Option<impl fmt::Display + 'b> { |
| 240 | id.as_os_str().to_str().map(str::to_string) |