diff options
Diffstat (limited to 'crates/ra_arena')
-rw-r--r-- | crates/ra_arena/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/ra_arena/src/map.rs | 10 |
2 files changed, 6 insertions, 24 deletions
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 97f554838..1c97c2662 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs | |||
@@ -44,10 +44,7 @@ pub struct Arena<ID: ArenaId, T> { | |||
44 | 44 | ||
45 | impl<ID: ArenaId, T: fmt::Debug> fmt::Debug for Arena<ID, T> { | 45 | impl<ID: ArenaId, T: fmt::Debug> fmt::Debug for Arena<ID, T> { |
46 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 46 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
47 | fmt.debug_struct("Arena") | 47 | fmt.debug_struct("Arena").field("len", &self.len()).field("data", &self.data).finish() |
48 | .field("len", &self.len()) | ||
49 | .field("data", &self.data) | ||
50 | .finish() | ||
51 | } | 48 | } |
52 | } | 49 | } |
53 | 50 | ||
@@ -80,19 +77,13 @@ impl<ID: ArenaId, T> Arena<ID, T> { | |||
80 | ID::from_raw(id) | 77 | ID::from_raw(id) |
81 | } | 78 | } |
82 | pub fn iter<'a>(&'a self) -> impl Iterator<Item = (ID, &'a T)> { | 79 | pub fn iter<'a>(&'a self) -> impl Iterator<Item = (ID, &'a T)> { |
83 | self.data | 80 | self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) |
84 | .iter() | ||
85 | .enumerate() | ||
86 | .map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) | ||
87 | } | 81 | } |
88 | } | 82 | } |
89 | 83 | ||
90 | impl<ID: ArenaId, T> Default for Arena<ID, T> { | 84 | impl<ID: ArenaId, T> Default for Arena<ID, T> { |
91 | fn default() -> Arena<ID, T> { | 85 | fn default() -> Arena<ID, T> { |
92 | Arena { | 86 | Arena { data: Vec::new(), _ty: PhantomData } |
93 | data: Vec::new(), | ||
94 | _ty: PhantomData, | ||
95 | } | ||
96 | } | 87 | } |
97 | } | 88 | } |
98 | 89 | ||
@@ -116,9 +107,6 @@ impl<ID: ArenaId, T> FromIterator<T> for Arena<ID, T> { | |||
116 | where | 107 | where |
117 | I: IntoIterator<Item = T>, | 108 | I: IntoIterator<Item = T>, |
118 | { | 109 | { |
119 | Arena { | 110 | Arena { data: Vec::from_iter(iter), _ty: PhantomData } |
120 | data: Vec::from_iter(iter), | ||
121 | _ty: PhantomData, | ||
122 | } | ||
123 | } | 111 | } |
124 | } | 112 | } |
diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs index be80edaf3..b73d4e365 100644 --- a/crates/ra_arena/src/map.rs +++ b/crates/ra_arena/src/map.rs | |||
@@ -42,10 +42,7 @@ impl<ID: ArenaId, T> ArenaMap<ID, T> { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> { | 44 | pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> { |
45 | self.v | 45 | self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) |
46 | .iter() | ||
47 | .enumerate() | ||
48 | .filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) | ||
49 | } | 46 | } |
50 | 47 | ||
51 | fn to_idx(id: ID) -> usize { | 48 | fn to_idx(id: ID) -> usize { |
@@ -66,9 +63,6 @@ impl<ID: ArenaId, T> std::ops::Index<ID> for ArenaMap<ID, T> { | |||
66 | 63 | ||
67 | impl<ID, T> Default for ArenaMap<ID, T> { | 64 | impl<ID, T> Default for ArenaMap<ID, T> { |
68 | fn default() -> Self { | 65 | fn default() -> Self { |
69 | ArenaMap { | 66 | ArenaMap { v: Vec::new(), _ty: PhantomData } |
70 | v: Vec::new(), | ||
71 | _ty: PhantomData, | ||
72 | } | ||
73 | } | 67 | } |
74 | } | 68 | } |