@@ -27,7 +27,7 @@ pub struct IndexVec<I: Idx, T> {
2727impl < I : Idx , T > IndexVec < I , T > {
2828 #[ inline]
2929 pub const fn new ( ) -> Self {
30- IndexVec { raw : Vec :: new ( ) , _marker : PhantomData }
30+ IndexVec :: from_raw ( Vec :: new ( ) )
3131 }
3232
3333 #[ inline]
@@ -37,7 +37,7 @@ impl<I: Idx, T> IndexVec<I, T> {
3737
3838 #[ inline]
3939 pub fn with_capacity ( capacity : usize ) -> Self {
40- IndexVec { raw : Vec :: with_capacity ( capacity) , _marker : PhantomData }
40+ IndexVec :: from_raw ( Vec :: with_capacity ( capacity) )
4141 }
4242
4343 /// Creates a new vector with a copy of `elem` for each index in `universe`.
@@ -56,24 +56,23 @@ impl<I: Idx, T> IndexVec<I, T> {
5656 where
5757 T : Clone ,
5858 {
59- IndexVec { raw : vec ! [ elem; universe. len( ) ] , _marker : PhantomData }
59+ IndexVec :: from_raw ( vec ! [ elem; universe. len( ) ] )
6060 }
6161
6262 #[ inline]
6363 pub fn from_elem_n ( elem : T , n : usize ) -> Self
6464 where
6565 T : Clone ,
6666 {
67- IndexVec { raw : vec ! [ elem; n] , _marker : PhantomData }
67+ IndexVec :: from_raw ( vec ! [ elem; n] )
6868 }
6969
7070 /// Create an `IndexVec` with `n` elements, where the value of each
7171 /// element is the result of `func(i)`. (The underlying vector will
7272 /// be allocated only once, with a capacity of at least `n`.)
7373 #[ inline]
7474 pub fn from_fn_n ( func : impl FnMut ( I ) -> T , n : usize ) -> Self {
75- let indices = ( 0 ..n) . map ( I :: new) ;
76- Self :: from_raw ( indices. map ( func) . collect ( ) )
75+ IndexVec :: from_raw ( ( 0 ..n) . map ( I :: new) . map ( func) . collect ( ) )
7776 }
7877
7978 #[ inline]
@@ -88,7 +87,7 @@ impl<I: Idx, T> IndexVec<I, T> {
8887
8988 #[ inline]
9089 pub fn push ( & mut self , d : T ) -> I {
91- let idx = I :: new ( self . len ( ) ) ;
90+ let idx = self . next_index ( ) ;
9291 self . raw . push ( d) ;
9392 idx
9493 }
@@ -139,7 +138,7 @@ impl<I: Idx, T> IndexVec<I, T> {
139138 }
140139
141140 pub fn convert_index_type < Ix : Idx > ( self ) -> IndexVec < Ix , T > {
142- IndexVec { raw : self . raw , _marker : PhantomData }
141+ IndexVec :: from_raw ( self . raw )
143142 }
144143
145144 /// Grows the index vector so that it contains an entry for
@@ -250,7 +249,7 @@ impl<I: Idx, T> FromIterator<T> for IndexVec<I, T> {
250249 where
251250 J : IntoIterator < Item = T > ,
252251 {
253- IndexVec { raw : FromIterator :: from_iter ( iter) , _marker : PhantomData }
252+ IndexVec :: from_raw ( Vec :: from_iter ( iter) )
254253 }
255254}
256255
@@ -270,7 +269,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T> {
270269
271270 #[ inline]
272271 fn into_iter ( self ) -> slice:: Iter < ' a , T > {
273- self . raw . iter ( )
272+ self . iter ( )
274273 }
275274}
276275
@@ -280,14 +279,14 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
280279
281280 #[ inline]
282281 fn into_iter ( self ) -> slice:: IterMut < ' a , T > {
283- self . raw . iter_mut ( )
282+ self . iter_mut ( )
284283 }
285284}
286285
287286impl < I : Idx , T > Default for IndexVec < I , T > {
288287 #[ inline]
289288 fn default ( ) -> Self {
290- Self :: new ( )
289+ IndexVec :: new ( )
291290 }
292291}
293292
@@ -308,7 +307,7 @@ impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
308307#[ cfg( feature = "rustc_serialize" ) ]
309308impl < D : Decoder , I : Idx , T : Decodable < D > > Decodable < D > for IndexVec < I , T > {
310309 fn decode ( d : & mut D ) -> Self {
311- IndexVec { raw : Decodable :: decode ( d) , _marker : PhantomData }
310+ IndexVec :: from_raw ( Vec :: < T > :: decode ( d) )
312311 }
313312}
314313
0 commit comments