aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_arena/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_arena/src/map.rs')
-rw-r--r--crates/ra_arena/src/map.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs
index c1b58712c..0f33907c0 100644
--- a/crates/ra_arena/src/map.rs
+++ b/crates/ra_arena/src/map.rs
@@ -13,18 +13,18 @@ pub struct ArenaMap<ID, V> {
13 13
14impl<T, V> ArenaMap<Idx<T>, V> { 14impl<T, V> ArenaMap<Idx<T>, V> {
15 pub fn insert(&mut self, id: Idx<T>, t: V) { 15 pub fn insert(&mut self, id: Idx<T>, t: V) {
16 let idx = Self::into_idx(id); 16 let idx = Self::to_idx(id);
17 17
18 self.v.resize_with((idx + 1).max(self.v.len()), || None); 18 self.v.resize_with((idx + 1).max(self.v.len()), || None);
19 self.v[idx] = Some(t); 19 self.v[idx] = Some(t);
20 } 20 }
21 21
22 pub fn get(&self, id: Idx<T>) -> Option<&V> { 22 pub fn get(&self, id: Idx<T>) -> Option<&V> {
23 self.v.get(Self::into_idx(id)).and_then(|it| it.as_ref()) 23 self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref())
24 } 24 }
25 25
26 pub fn get_mut(&mut self, id: Idx<T>) -> Option<&mut V> { 26 pub fn get_mut(&mut self, id: Idx<T>) -> Option<&mut V> {
27 self.v.get_mut(Self::into_idx(id)).and_then(|it| it.as_mut()) 27 self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut())
28 } 28 }
29 29
30 pub fn values(&self) -> impl Iterator<Item = &V> { 30 pub fn values(&self) -> impl Iterator<Item = &V> {
@@ -39,7 +39,7 @@ impl<T, V> ArenaMap<Idx<T>, V> {
39 self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) 39 self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?)))
40 } 40 }
41 41
42 fn into_idx(id: Idx<T>) -> usize { 42 fn to_idx(id: Idx<T>) -> usize {
43 u32::from(id.into_raw()) as usize 43 u32::from(id.into_raw()) as usize
44 } 44 }
45 45
@@ -51,7 +51,7 @@ impl<T, V> ArenaMap<Idx<T>, V> {
51impl<T, V> std::ops::Index<Idx<V>> for ArenaMap<Idx<V>, T> { 51impl<T, V> std::ops::Index<Idx<V>> for ArenaMap<Idx<V>, T> {
52 type Output = T; 52 type Output = T;
53 fn index(&self, id: Idx<V>) -> &T { 53 fn index(&self, id: Idx<V>) -> &T {
54 self.v[Self::into_idx(id)].as_ref().unwrap() 54 self.v[Self::to_idx(id)].as_ref().unwrap()
55 } 55 }
56} 56}
57 57