1#![feature(new_range_api)]
2
3use oak_core::{
4 Arc,
5 source::{Source, SourceId},
6};
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10mod line_map;
11pub use line_map::LineMap;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16pub enum FileType {
17 File,
18 Directory,
19 Other,
20}
21
22#[derive(Debug, Clone)]
24#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
25pub struct FileMetadata {
26 pub file_type: FileType,
27 pub len: u64,
28 pub modified: Option<u64>, }
30
31pub mod vfs;
32pub use vfs::MemoryVfs;
33#[cfg(feature = "disk")]
34pub use vfs::{DiskVfs, DiskWatcher, VfsEvent, VfsWatcher};
35
36pub trait Vfs: Send + Sync {
38 type Source: Source + 'static;
40
41 fn get_source(&self, uri: &str) -> Option<Self::Source>;
43
44 fn get_uri(&self, id: SourceId) -> Option<Arc<str>>;
46
47 fn get_id(&self, uri: &str) -> Option<SourceId>;
49
50 fn exists(&self, uri: &str) -> bool;
52
53 fn metadata(&self, uri: &str) -> Option<FileMetadata>;
55
56 fn read_dir(&self, uri: &str) -> Option<Vec<Arc<str>>>;
59
60 fn is_file(&self, uri: &str) -> bool {
62 self.metadata(uri).map(|m| m.file_type == FileType::File).unwrap_or(false)
63 }
64
65 fn is_dir(&self, uri: &str) -> bool {
67 self.metadata(uri).map(|m| m.file_type == FileType::Directory).unwrap_or(false)
68 }
69
70 fn line_map(&self, uri: &str) -> Option<LineMap> {
71 self.get_source(uri).map(|s| LineMap::from_source(&s))
72 }
73}
74
75pub trait WritableVfs: Vfs {
77 fn write_file(&self, uri: &str, content: Arc<str>);
79
80 fn remove_file(&self, uri: &str);
82}