From 291d578938d7dc9b1f9bbd1174e444cc831531d9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 4 Jan 2019 16:01:06 +0300 Subject: extract area to a crate --- crates/ra_vfs/src/arena.rs | 53 ---------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 crates/ra_vfs/src/arena.rs (limited to 'crates/ra_vfs/src/arena.rs') 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 @@ -use std::{ - marker::PhantomData, - ops::{Index, IndexMut}, -}; - -#[derive(Clone, Debug)] -pub(crate) struct Arena { - data: Vec, - _ty: PhantomData, -} - -pub(crate) trait ArenaId { - fn from_u32(id: u32) -> Self; - fn to_u32(self) -> u32; -} - -impl Arena { - pub fn alloc(&mut self, value: T) -> ID { - let id = self.data.len() as u32; - self.data.push(value); - ID::from_u32(id) - } - pub fn iter<'a>(&'a self) -> impl Iterator { - self.data - .iter() - .enumerate() - .map(|(idx, value)| (ID::from_u32(idx as u32), value)) - } -} - -impl Default for Arena { - fn default() -> Arena { - Arena { - data: Vec::new(), - _ty: PhantomData, - } - } -} - -impl Index for Arena { - type Output = T; - fn index(&self, idx: ID) -> &T { - let idx = idx.to_u32() as usize; - &self.data[idx] - } -} - -impl IndexMut for Arena { - fn index_mut(&mut self, idx: ID) -> &mut T { - let idx = idx.to_u32() as usize; - &mut self.data[idx] - } -} -- cgit v1.2.3