34 lines
663 B
Rust
34 lines
663 B
Rust
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct FileStore {
|
|
files: Vec<SourceFile>,
|
|
}
|
|
|
|
impl FileStore {
|
|
pub fn add(&mut self, file: SourceFile) -> FileId {
|
|
let id = FileId(self.files.len());
|
|
self.files.push(file);
|
|
id
|
|
}
|
|
|
|
pub fn get(&self, id: FileId) -> &SourceFile {
|
|
&self.files[id.0]
|
|
}
|
|
}
|
|
|
|
impl From<Vec<SourceFile>> for FileStore {
|
|
fn from(files: Vec<SourceFile>) -> Self {
|
|
Self { files }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct SourceFile {
|
|
pub path: PathBuf,
|
|
pub source: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
|
|
pub struct FileId(usize);
|