17
17
18
18
#![ cfg_attr( not( feature = "std" ) , no_std) ]
19
19
#![ cfg_attr( not( feature = "std" ) , feature( alloc) ) ]
20
+ #![ deny( missing_docs) ]
20
21
21
22
22
23
#[ cfg( not( feature = "std" ) ) ]
@@ -135,6 +136,11 @@ unsafe fn deallocate<T>(ptr: *mut T, capacity: usize) {
135
136
// Let it drop.
136
137
}
137
138
139
+ /// An iterator that removes the items from a `SmallVec` and yields them by value.
140
+ ///
141
+ /// Returned from [`SmallVec::drain`][1].
142
+ ///
143
+ /// [1]: struct.SmallVec.html#method.drain
138
144
pub struct Drain < ' a , T : ' a > {
139
145
iter : slice:: IterMut < ' a , T > ,
140
146
}
@@ -590,6 +596,8 @@ impl<A: Array> SmallVec<A> {
590
596
}
591
597
}
592
598
599
+ /// Insert multiple elements at position `index`, shifting all following elements toward the
600
+ /// back.
593
601
pub fn insert_many < I : IntoIterator < Item =A :: Item > > ( & mut self , index : usize , iterable : I ) {
594
602
let iter = iterable. into_iter ( ) ;
595
603
let ( lower_size_bound, _) = iter. size_hint ( ) ;
@@ -697,12 +705,19 @@ impl<A: Array> SmallVec<A> {
697
705
}
698
706
699
707
impl < A : Array > SmallVec < A > where A :: Item : Copy {
708
+ /// Copy the elements from a slice into a new `SmallVec`.
709
+ ///
710
+ /// For slices of `Copy` types, this is more efficient than `SmallVec::from(slice)`.
700
711
pub fn from_slice ( slice : & [ A :: Item ] ) -> Self {
701
712
let mut vec = Self :: new ( ) ;
702
713
vec. extend_from_slice ( slice) ;
703
714
vec
704
715
}
705
716
717
+ /// Copy elements from a slice into the vector at position `index`, shifting any following
718
+ /// elements toward the back.
719
+ ///
720
+ /// For slices of `Copy` types, this is more efficient than `insert`.
706
721
pub fn insert_from_slice ( & mut self , index : usize , slice : & [ A :: Item ] ) {
707
722
self . reserve ( slice. len ( ) ) ;
708
723
@@ -718,6 +733,9 @@ impl<A: Array> SmallVec<A> where A::Item: Copy {
718
733
}
719
734
}
720
735
736
+ /// Copy elements from a slice and append them to the vector.
737
+ ///
738
+ /// For slices of `Copy` types, this is more efficient than `extend`.
721
739
#[ inline]
722
740
pub fn extend_from_slice ( & mut self , slice : & [ A :: Item ] ) {
723
741
let len = self . len ( ) ;
@@ -997,6 +1015,11 @@ impl<A: Array> Hash for SmallVec<A> where A::Item: Hash {
997
1015
998
1016
unsafe impl < A : Array > Send for SmallVec < A > where A :: Item : Send { }
999
1017
1018
+ /// An iterator that consumes a `SmallVec` and yields its items by value.
1019
+ ///
1020
+ /// Returned from [`SmallVec::into_iter`][1].
1021
+ ///
1022
+ /// [1]: struct.SmallVec.html#method.into_iter
1000
1023
pub struct IntoIter < A : Array > {
1001
1024
data : SmallVecData < A > ,
1002
1025
current : usize ,
@@ -1116,9 +1139,13 @@ pub type SmallVec32<T> = SmallVec<[T; 32]>;
1116
1139
1117
1140
/// Types that can be used as the backing store for a SmallVec
1118
1141
pub unsafe trait Array {
1142
+ /// The type of the array's elements.
1119
1143
type Item ;
1144
+ /// Returns the number of items the array can hold.
1120
1145
fn size ( ) -> usize ;
1146
+ /// Returns a pointer to the first element of the array.
1121
1147
fn ptr ( & self ) -> * const Self :: Item ;
1148
+ /// Returns a mutable pointer to the first element of the array.
1122
1149
fn ptr_mut ( & mut self ) -> * mut Self :: Item ;
1123
1150
}
1124
1151
@@ -1140,7 +1167,7 @@ impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 3
1140
1167
0x10000 , 0x20000 , 0x40000 , 0x80000 , 0x100000 ) ;
1141
1168
1142
1169
#[ cfg( test) ]
1143
- pub mod tests {
1170
+ mod tests {
1144
1171
use SmallVec ;
1145
1172
1146
1173
use std:: iter:: FromIterator ;
0 commit comments