aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs/src')
-rw-r--r--crates/ra_vfs/src/arena.rs53
-rw-r--r--crates/ra_vfs/src/lib.rs34
2 files changed, 7 insertions, 80 deletions
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 @@
1use std::{
2 marker::PhantomData,
3 ops::{Index, IndexMut},
4};
5
6#[derive(Clone, Debug)]
7pub(crate) struct Arena<ID: ArenaId, T> {
8 data: Vec<T>,
9 _ty: PhantomData<ID>,
10}
11
12pub(crate) trait ArenaId {
13 fn from_u32(id: u32) -> Self;
14 fn to_u32(self) -> u32;
15}
16
17impl<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
31impl<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
40impl<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
48impl<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.
16mod arena;
17mod io; 16mod io;
18 17
19use std::{ 18use std::{
@@ -32,10 +31,7 @@ use relative_path::RelativePathBuf;
32use crossbeam_channel::Receiver; 31use crossbeam_channel::Receiver;
33use walkdir::DirEntry; 32use walkdir::DirEntry;
34use thread_worker::WorkerHandle; 33use thread_worker::WorkerHandle;
35 34use ra_arena::{Arena, RawId, impl_arena_id};
36use crate::{
37 arena::{ArenaId, Arena},
38};
39 35
40pub use crate::io::TaskResult as VfsTask; 36pub 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)]
72pub struct VfsRoot(pub u32); 68pub struct VfsRoot(pub RawId);
73 69impl_arena_id!(VfsRoot);
74impl 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)]
84pub struct VfsFile(pub u32);
85 70
86impl ArenaId for VfsFile { 71#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
87 fn from_u32(idx: u32) -> VfsFile { 72pub struct VfsFile(pub RawId);
88 VfsFile(idx) 73impl_arena_id!(VfsFile);
89 }
90 fn to_u32(self) -> u32 {
91 self.0
92 }
93}
94 74
95struct VfsFileData { 75struct VfsFileData {
96 root: VfsRoot, 76 root: VfsRoot,