@@ -12,10 +12,13 @@ use std::vec;
12
12
use crate :: { Idx , IndexSlice } ;
13
13
14
14
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
15
+ /// Its purpose is to avoid mixing indexes.
15
16
///
16
17
/// While it's possible to use `u32` or `usize` directly for `I`,
17
18
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
18
19
///
20
+ /// This allows to index the IndexVec with the new index type.
21
+ ///
19
22
/// [`newtype_index!`]: ../macro.newtype_index.html
20
23
#[ derive( Clone , PartialEq , Eq , Hash ) ]
21
24
#[ repr( transparent) ]
@@ -25,11 +28,13 @@ pub struct IndexVec<I: Idx, T> {
25
28
}
26
29
27
30
impl < I : Idx , T > IndexVec < I , T > {
31
+ /// Constructs a new, empty `IndexVec<I, T>`.
28
32
#[ inline]
29
33
pub const fn new ( ) -> Self {
30
34
IndexVec :: from_raw ( Vec :: new ( ) )
31
35
}
32
36
37
+ /// Constructs a new `IndexVec<I, T>` from a `Vec<T>`.
33
38
#[ inline]
34
39
pub const fn from_raw ( raw : Vec < T > ) -> Self {
35
40
IndexVec { raw, _marker : PhantomData }
@@ -59,6 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> {
59
64
IndexVec :: from_raw ( vec ! [ elem; universe. len( ) ] )
60
65
}
61
66
67
+ /// Creates a new IndexVec with n copies of the `elem`.
62
68
#[ inline]
63
69
pub fn from_elem_n ( elem : T , n : usize ) -> Self
64
70
where
@@ -85,6 +91,7 @@ impl<I: Idx, T> IndexVec<I, T> {
85
91
IndexSlice :: from_raw_mut ( & mut self . raw )
86
92
}
87
93
94
+ /// Pushes an element to the array returning the index where it was pushed to.
88
95
#[ inline]
89
96
pub fn push ( & mut self , d : T ) -> I {
90
97
let idx = self . next_index ( ) ;
0 commit comments