aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/src/arena.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-04 13:58:41 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-04 13:58:41 +0000
commita0d483011d5f84747fcc5d5fe9c82f4405d24db9 (patch)
tree25bc6aab1e4328e73446876b274e7dcaff7aa915 /crates/ra_vfs/src/arena.rs
parent821fa7a50ab8c4886adc60a2093aa8e06cc3a9d6 (diff)
parent3fe6f422f9ef13b9171dbeab0c5c427f729f9983 (diff)
Merge #425
425: remove id arena r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_vfs/src/arena.rs')
-rw-r--r--crates/ra_vfs/src/arena.rs53
1 files changed, 0 insertions, 53 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}