diff options
Diffstat (limited to 'crates/ra_vfs')
-rw-r--r-- | crates/ra_vfs/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_vfs/src/arena.rs | 53 | ||||
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 34 |
3 files changed, 8 insertions, 80 deletions
diff --git a/crates/ra_vfs/Cargo.toml b/crates/ra_vfs/Cargo.toml index 7c170cdfc..e637063c9 100644 --- a/crates/ra_vfs/Cargo.toml +++ b/crates/ra_vfs/Cargo.toml | |||
@@ -12,6 +12,7 @@ crossbeam-channel = "0.3.5" | |||
12 | log = "0.4.6" | 12 | log = "0.4.6" |
13 | 13 | ||
14 | thread_worker = { path = "../thread_worker" } | 14 | thread_worker = { path = "../thread_worker" } |
15 | ra_arena = { path = "../ra_arena" } | ||
15 | 16 | ||
16 | [dev-dependencies] | 17 | [dev-dependencies] |
17 | tempfile = "3" | 18 | tempfile = "3" |
diff --git a/crates/ra_vfs/src/arena.rs b/crates/ra_vfs/src/arena.rs deleted file mode 100644 index 6b42ae26d..000000000 --- a/crates/ra_vfs/src/arena.rs +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | use std::{ | ||
2 | marker::PhantomData, | ||
3 | ops::{Index, IndexMut}, | ||
4 | }; | ||
5 | |||
6 | #[derive(Clone, Debug)] | ||
7 | pub(crate) struct Arena<ID: ArenaId, T> { | ||
8 | data: Vec<T>, | ||
9 | _ty: PhantomData<ID>, | ||
10 | } | ||
11 | |||
12 | pub(crate) trait ArenaId { | ||
13 | fn from_u32(id: u32) -> Self; | ||
14 | fn to_u32(self) -> u32; | ||
15 | } | ||
16 | |||
17 | impl<ID: ArenaId, T> Arena<ID, T> { | ||
18 | pub fn alloc(&mut self, value: T) -> ID { | ||
19 | let id = self.data.len() as u32; | ||
20 | self.data.push(value); | ||
21 | ID::from_u32(id) | ||
22 | } | ||
23 | pub fn iter<'a>(&'a self) -> impl Iterator<Item = (ID, &'a T)> { | ||
24 | self.data | ||
25 | .iter() | ||
26 | .enumerate() | ||
27 | .map(|(idx, value)| (ID::from_u32(idx as u32), value)) | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl<ID: ArenaId, T> Default for Arena<ID, T> { | ||
32 | fn default() -> Arena<ID, T> { | ||
33 | Arena { | ||
34 | data: Vec::new(), | ||
35 | _ty: PhantomData, | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | |||
40 | impl<ID: ArenaId, T> Index<ID> for Arena<ID, T> { | ||
41 | type Output = T; | ||
42 | fn index(&self, idx: ID) -> &T { | ||
43 | let idx = idx.to_u32() as usize; | ||
44 | &self.data[idx] | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl<ID: ArenaId, T> IndexMut<ID> for Arena<ID, T> { | ||
49 | fn index_mut(&mut self, idx: ID) -> &mut T { | ||
50 | let idx = idx.to_u32() as usize; | ||
51 | &mut self.data[idx] | ||
52 | } | ||
53 | } | ||
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 5bbc3e993..cdea18d73 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -13,7 +13,6 @@ | |||
13 | //! VFS is based on a concept of roots: a set of directories on the file system | 13 | //! VFS is based on a concept of roots: a set of directories on the file system |
14 | //! which are watched for changes. Typically, there will be a root for each | 14 | //! which are watched for changes. Typically, there will be a root for each |
15 | //! Cargo package. | 15 | //! Cargo package. |
16 | mod arena; | ||
17 | mod io; | 16 | mod io; |
18 | 17 | ||
19 | use std::{ | 18 | use std::{ |
@@ -32,10 +31,7 @@ use relative_path::RelativePathBuf; | |||
32 | use crossbeam_channel::Receiver; | 31 | use crossbeam_channel::Receiver; |
33 | use walkdir::DirEntry; | 32 | use walkdir::DirEntry; |
34 | use thread_worker::WorkerHandle; | 33 | use thread_worker::WorkerHandle; |
35 | 34 | use ra_arena::{Arena, RawId, impl_arena_id}; | |
36 | use crate::{ | ||
37 | arena::{ArenaId, Arena}, | ||
38 | }; | ||
39 | 35 | ||
40 | pub use crate::io::TaskResult as VfsTask; | 36 | pub use crate::io::TaskResult as VfsTask; |
41 | 37 | ||
@@ -68,29 +64,13 @@ fn has_rs_extension(p: &Path) -> bool { | |||
68 | p.extension() == Some(OsStr::new("rs")) | 64 | p.extension() == Some(OsStr::new("rs")) |
69 | } | 65 | } |
70 | 66 | ||
71 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | 67 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
72 | pub struct VfsRoot(pub u32); | 68 | pub struct VfsRoot(pub RawId); |
73 | 69 | impl_arena_id!(VfsRoot); | |
74 | impl ArenaId for VfsRoot { | ||
75 | fn from_u32(idx: u32) -> VfsRoot { | ||
76 | VfsRoot(idx) | ||
77 | } | ||
78 | fn to_u32(self) -> u32 { | ||
79 | self.0 | ||
80 | } | ||
81 | } | ||
82 | |||
83 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
84 | pub struct VfsFile(pub u32); | ||
85 | 70 | ||
86 | impl ArenaId for VfsFile { | 71 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
87 | fn from_u32(idx: u32) -> VfsFile { | 72 | pub struct VfsFile(pub RawId); |
88 | VfsFile(idx) | 73 | impl_arena_id!(VfsFile); |
89 | } | ||
90 | fn to_u32(self) -> u32 { | ||
91 | self.0 | ||
92 | } | ||
93 | } | ||
94 | 74 | ||
95 | struct VfsFileData { | 75 | struct VfsFileData { |
96 | root: VfsRoot, | 76 | root: VfsRoot, |