1#![feature(new_range_api)]
2
3use oak_core::source::Source;
4use serde::{Deserialize, Serialize};
5
6mod line_map;
7pub use line_map::LineMap;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum FileType {
12 File,
13 Directory,
14 Other,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct FileMetadata {
20 pub file_type: FileType,
21 pub len: u64,
22 pub modified: Option<u64>, }
24
25pub mod vfs;
26pub use vfs::{DiskVfs, MemoryVfs};
27
28pub trait Vfs: Send + Sync {
30 type Source: Source + 'static;
32
33 fn get_source(&self, uri: &str) -> Option<Self::Source>;
35
36 fn exists(&self, uri: &str) -> bool;
38
39 fn metadata(&self, uri: &str) -> Option<FileMetadata>;
41
42 fn read_dir(&self, uri: &str) -> Option<Vec<String>>;
45
46 fn is_file(&self, uri: &str) -> bool {
48 self.metadata(uri).map(|m| m.file_type == FileType::File).unwrap_or(false)
49 }
50
51 fn is_dir(&self, uri: &str) -> bool {
53 self.metadata(uri).map(|m| m.file_type == FileType::Directory).unwrap_or(false)
54 }
55
56 fn line_map(&self, uri: &str) -> Option<LineMap> {
57 self.get_source(uri).map(|s| LineMap::from_source(&s))
58 }
59}
60
61pub trait WritableVfs: Vfs {
63 fn write_file(&self, uri: &str, content: String);
65
66 fn remove_file(&self, uri: &str);
68}