Document vfs private items

This commit is contained in:
Arnaud 2021-01-12 17:41:45 +01:00
parent 311ec70d03
commit 4b71c8332d
5 changed files with 117 additions and 2 deletions

View file

@ -5,6 +5,7 @@ use rustc_hash::FxHashMap;
use crate::{FileId, VfsPath};
/// Structure to map between [`VfsPath`] and [`FileId`].
#[derive(Default)]
pub(crate) struct PathInterner {
map: FxHashMap<VfsPath, FileId>,
@ -12,9 +13,17 @@ pub(crate) struct PathInterner {
}
impl PathInterner {
/// Get the id corresponding to `path`.
///
/// If `path` does not exists in `self`, returns [`None`].
pub(crate) fn get(&self, path: &VfsPath) -> Option<FileId> {
self.map.get(path).copied()
}
/// Insert `path` in `self`.
///
/// - If `path` already exists in `self`, returns its associated id;
/// - Else, returns a newly allocated id.
pub(crate) fn intern(&mut self, path: VfsPath) -> FileId {
if let Some(id) = self.get(&path) {
return id;
@ -25,6 +34,11 @@ impl PathInterner {
id
}
/// Returns the path corresponding to `id`.
///
/// # Panics
///
/// Panics if `id` does not exists in `self`.
pub(crate) fn lookup(&self, id: FileId) -> &VfsPath {
&self.vec[id.0 as usize]
}