@@ -27,7 +27,7 @@ pub struct IndexVec<I: Idx, T> {
27
27
impl < I : Idx , T > IndexVec < I , T > {
28
28
#[ inline]
29
29
pub const fn new ( ) -> Self {
30
- IndexVec { raw : Vec :: new ( ) , _marker : PhantomData }
30
+ IndexVec :: from_raw ( Vec :: new ( ) )
31
31
}
32
32
33
33
#[ inline]
@@ -37,7 +37,7 @@ impl<I: Idx, T> IndexVec<I, T> {
37
37
38
38
#[ inline]
39
39
pub fn with_capacity ( capacity : usize ) -> Self {
40
- IndexVec { raw : Vec :: with_capacity ( capacity) , _marker : PhantomData }
40
+ IndexVec :: from_raw ( Vec :: with_capacity ( capacity) )
41
41
}
42
42
43
43
/// 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> {
56
56
where
57
57
T : Clone ,
58
58
{
59
- IndexVec { raw : vec ! [ elem; universe. len( ) ] , _marker : PhantomData }
59
+ IndexVec :: from_raw ( vec ! [ elem; universe. len( ) ] )
60
60
}
61
61
62
62
#[ inline]
63
63
pub fn from_elem_n ( elem : T , n : usize ) -> Self
64
64
where
65
65
T : Clone ,
66
66
{
67
- IndexVec { raw : vec ! [ elem; n] , _marker : PhantomData }
67
+ IndexVec :: from_raw ( vec ! [ elem; n] )
68
68
}
69
69
70
70
/// Create an `IndexVec` with `n` elements, where the value of each
71
71
/// element is the result of `func(i)`. (The underlying vector will
72
72
/// be allocated only once, with a capacity of at least `n`.)
73
73
#[ inline]
74
74
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 ( ) )
77
76
}
78
77
79
78
#[ inline]
@@ -88,7 +87,7 @@ impl<I: Idx, T> IndexVec<I, T> {
88
87
89
88
#[ inline]
90
89
pub fn push ( & mut self , d : T ) -> I {
91
- let idx = I :: new ( self . len ( ) ) ;
90
+ let idx = self . next_index ( ) ;
92
91
self . raw . push ( d) ;
93
92
idx
94
93
}
@@ -139,7 +138,7 @@ impl<I: Idx, T> IndexVec<I, T> {
139
138
}
140
139
141
140
pub fn convert_index_type < Ix : Idx > ( self ) -> IndexVec < Ix , T > {
142
- IndexVec { raw : self . raw , _marker : PhantomData }
141
+ IndexVec :: from_raw ( self . raw )
143
142
}
144
143
145
144
/// 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> {
250
249
where
251
250
J : IntoIterator < Item = T > ,
252
251
{
253
- IndexVec { raw : FromIterator :: from_iter ( iter) , _marker : PhantomData }
252
+ IndexVec :: from_raw ( Vec :: from_iter ( iter) )
254
253
}
255
254
}
256
255
@@ -270,7 +269,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T> {
270
269
271
270
#[ inline]
272
271
fn into_iter ( self ) -> slice:: Iter < ' a , T > {
273
- self . raw . iter ( )
272
+ self . iter ( )
274
273
}
275
274
}
276
275
@@ -280,14 +279,14 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
280
279
281
280
#[ inline]
282
281
fn into_iter ( self ) -> slice:: IterMut < ' a , T > {
283
- self . raw . iter_mut ( )
282
+ self . iter_mut ( )
284
283
}
285
284
}
286
285
287
286
impl < I : Idx , T > Default for IndexVec < I , T > {
288
287
#[ inline]
289
288
fn default ( ) -> Self {
290
- Self :: new ( )
289
+ IndexVec :: new ( )
291
290
}
292
291
}
293
292
@@ -308,7 +307,7 @@ impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
308
307
#[ cfg( feature = "rustc_serialize" ) ]
309
308
impl < D : Decoder , I : Idx , T : Decodable < D > > Decodable < D > for IndexVec < I , T > {
310
309
fn decode ( d : & mut D ) -> Self {
311
- IndexVec { raw : Decodable :: decode ( d) , _marker : PhantomData }
310
+ IndexVec :: from_raw ( Vec :: < T > :: decode ( d) )
312
311
}
313
312
}
314
313
0 commit comments