@@ -46,10 +46,15 @@ const MAXIMUM_ZST_CAPACITY: usize = 1 << (64 - 1); // Largest possible power of
46
46
/// `VecDeque` is a growable ring buffer, which can be used as a double-ended
47
47
/// queue efficiently.
48
48
///
49
- /// The "default" usage of this type as a queue is to use `push_back` to add to
50
- /// the queue, and `pop_front` to remove from the queue. `extend` and `append`
49
+ /// The "default" usage of this type as a queue is to use [ `push_back`] to add to
50
+ /// the queue, and [ `pop_front`] to remove from the queue. [ `extend`] and [ `append`]
51
51
/// push onto the back in this manner, and iterating over `VecDeque` goes front
52
52
/// to back.
53
+ ///
54
+ /// [`push_back`]: #method.push_back
55
+ /// [`pop_front`]: #method.pop_front
56
+ /// [`extend`]: #method.extend
57
+ /// [`append`]: #method.append
53
58
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
54
59
pub struct VecDeque < T > {
55
60
// tail and head are pointers into the buffer. Tail always points
@@ -92,13 +97,13 @@ impl<T> Default for VecDeque<T> {
92
97
}
93
98
94
99
impl < T > VecDeque < T > {
95
- /// Marginally more convenient
100
+ /// Marginally more convenient.
96
101
#[ inline]
97
102
fn ptr ( & self ) -> * mut T {
98
103
self . buf . ptr ( )
99
104
}
100
105
101
- /// Marginally more convenient
106
+ /// Marginally more convenient.
102
107
#[ inline]
103
108
fn cap ( & self ) -> usize {
104
109
if mem:: size_of :: < T > ( ) == 0 {
@@ -109,19 +114,19 @@ impl<T> VecDeque<T> {
109
114
}
110
115
}
111
116
112
- /// Turn ptr into a slice
117
+ /// Turn ptr into a slice.
113
118
#[ inline]
114
119
unsafe fn buffer_as_slice ( & self ) -> & [ T ] {
115
120
slice:: from_raw_parts ( self . ptr ( ) , self . cap ( ) )
116
121
}
117
122
118
- /// Turn ptr into a mut slice
123
+ /// Turn ptr into a mut slice.
119
124
#[ inline]
120
125
unsafe fn buffer_as_mut_slice ( & mut self ) -> & mut [ T ] {
121
126
slice:: from_raw_parts_mut ( self . ptr ( ) , self . cap ( ) )
122
127
}
123
128
124
- /// Moves an element out of the buffer
129
+ /// Moves an element out of the buffer.
125
130
#[ inline]
126
131
unsafe fn buffer_read ( & mut self , off : usize ) -> T {
127
132
ptr:: read ( self . ptr ( ) . offset ( off as isize ) )
@@ -133,7 +138,7 @@ impl<T> VecDeque<T> {
133
138
ptr:: write ( self . ptr ( ) . offset ( off as isize ) , value) ;
134
139
}
135
140
136
- /// Returns true if and only if the buffer is at capacity
141
+ /// Returns true if and only if the buffer is at capacity.
137
142
#[ inline]
138
143
fn is_full ( & self ) -> bool {
139
144
self . cap ( ) - self . len ( ) == 1
@@ -506,12 +511,15 @@ impl<T> VecDeque<T> {
506
511
/// given `VecDeque`. Does nothing if the capacity is already sufficient.
507
512
///
508
513
/// Note that the allocator may give the collection more space than it requests. Therefore
509
- /// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
514
+ /// capacity can not be relied upon to be precisely minimal. Prefer [ `reserve`] if future
510
515
/// insertions are expected.
511
516
///
512
517
/// # Panics
513
518
///
514
- /// Panics if the new capacity overflows `usize`.
519
+ /// Panics if the new capacity overflows [`usize`].
520
+ ///
521
+ /// [`reserve`]: #method.reserve
522
+ /// [`usize`]: ../../std/primitive.usize.html
515
523
///
516
524
/// # Examples
517
525
///
@@ -532,7 +540,9 @@ impl<T> VecDeque<T> {
532
540
///
533
541
/// # Panics
534
542
///
535
- /// Panics if the new capacity overflows `usize`.
543
+ /// Panics if the new capacity overflows [`usize`].
544
+ ///
545
+ /// [`usize`]: ../../std/primitive.usize.html
536
546
///
537
547
/// # Examples
538
548
///
@@ -788,7 +798,7 @@ impl<T> VecDeque<T> {
788
798
count ( self . tail , self . head , self . cap ( ) )
789
799
}
790
800
791
- /// Returns true if the buffer contains no elements
801
+ /// Returns true if the buffer contains no elements.
792
802
///
793
803
/// # Examples
794
804
///
@@ -812,14 +822,17 @@ impl<T> VecDeque<T> {
812
822
/// consumed until the end.
813
823
///
814
824
/// Note 2: It is unspecified how many elements are removed from the deque,
815
- /// if the `Drain` value is not dropped, but the borrow it holds expires
816
- /// (eg. due to mem::forget).
825
+ /// if the [ `Drain`] value is not dropped, but the borrow it holds expires
826
+ /// (eg. due to [` mem::forget`] ).
817
827
///
818
828
/// # Panics
819
829
///
820
830
/// Panics if the starting point is greater than the end point or if
821
831
/// the end point is greater than the length of the vector.
822
832
///
833
+ /// [`Drain`]: ../../std/collections/vec_deque/struct.Drain.html
834
+ /// [`mem::forget`]: ../../std/mem/fn.forget.html
835
+ ///
823
836
/// # Examples
824
837
///
825
838
/// ```
@@ -941,9 +954,11 @@ impl<T> VecDeque<T> {
941
954
a. contains ( x) || b. contains ( x)
942
955
}
943
956
944
- /// Provides a reference to the front element, or `None` if the sequence is
957
+ /// Provides a reference to the front element, or [ `None`] if the sequence is
945
958
/// empty.
946
959
///
960
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
961
+ ///
947
962
/// # Examples
948
963
///
949
964
/// ```
@@ -965,9 +980,11 @@ impl<T> VecDeque<T> {
965
980
}
966
981
}
967
982
968
- /// Provides a mutable reference to the front element, or `None` if the
983
+ /// Provides a mutable reference to the front element, or [ `None`] if the
969
984
/// sequence is empty.
970
985
///
986
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
987
+ ///
971
988
/// # Examples
972
989
///
973
990
/// ```
@@ -993,9 +1010,11 @@ impl<T> VecDeque<T> {
993
1010
}
994
1011
}
995
1012
996
- /// Provides a reference to the back element, or `None` if the sequence is
1013
+ /// Provides a reference to the back element, or [ `None`] if the sequence is
997
1014
/// empty.
998
1015
///
1016
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1017
+ ///
999
1018
/// # Examples
1000
1019
///
1001
1020
/// ```
@@ -1017,9 +1036,11 @@ impl<T> VecDeque<T> {
1017
1036
}
1018
1037
}
1019
1038
1020
- /// Provides a mutable reference to the back element, or `None` if the
1039
+ /// Provides a mutable reference to the back element, or [ `None`] if the
1021
1040
/// sequence is empty.
1022
1041
///
1042
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1043
+ ///
1023
1044
/// # Examples
1024
1045
///
1025
1046
/// ```
@@ -1046,9 +1067,11 @@ impl<T> VecDeque<T> {
1046
1067
}
1047
1068
}
1048
1069
1049
- /// Removes the first element and returns it, or `None` if the sequence is
1070
+ /// Removes the first element and returns it, or [ `None`] if the sequence is
1050
1071
/// empty.
1051
1072
///
1073
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1074
+ ///
1052
1075
/// # Examples
1053
1076
///
1054
1077
/// ```
@@ -1131,9 +1154,11 @@ impl<T> VecDeque<T> {
1131
1154
unsafe { self . buffer_write ( head, value) }
1132
1155
}
1133
1156
1134
- /// Removes the last element from a buffer and returns it, or `None` if
1157
+ /// Removes the last element from a buffer and returns it, or [ `None`] if
1135
1158
/// it is empty.
1136
1159
///
1160
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1161
+ ///
1137
1162
/// # Examples
1138
1163
///
1139
1164
/// ```
@@ -1166,10 +1191,12 @@ impl<T> VecDeque<T> {
1166
1191
///
1167
1192
/// This does not preserve ordering, but is O(1).
1168
1193
///
1169
- /// Returns `None` if `index` is out of bounds.
1194
+ /// Returns [ `None`] if `index` is out of bounds.
1170
1195
///
1171
1196
/// Element at index 0 is the front of the queue.
1172
1197
///
1198
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1199
+ ///
1173
1200
/// # Examples
1174
1201
///
1175
1202
/// ```
@@ -1201,10 +1228,12 @@ impl<T> VecDeque<T> {
1201
1228
///
1202
1229
/// This does not preserve ordering, but is O(1).
1203
1230
///
1204
- /// Returns `None` if `index` is out of bounds.
1231
+ /// Returns [ `None`] if `index` is out of bounds.
1205
1232
///
1206
1233
/// Element at index 0 is the front of the queue.
1207
1234
///
1235
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1236
+ ///
1208
1237
/// # Examples
1209
1238
///
1210
1239
/// ```
@@ -1238,7 +1267,7 @@ impl<T> VecDeque<T> {
1238
1267
///
1239
1268
/// # Panics
1240
1269
///
1241
- /// Panics if `index` is greater than `VecDeque`'s length
1270
+ /// Panics if `index` is greater than `VecDeque`'s length.
1242
1271
///
1243
1272
/// # Examples
1244
1273
///
@@ -1463,10 +1492,12 @@ impl<T> VecDeque<T> {
1463
1492
/// Removes and returns the element at `index` from the `VecDeque`.
1464
1493
/// Whichever end is closer to the removal point will be moved to make
1465
1494
/// room, and all the affected elements will be moved to new positions.
1466
- /// Returns `None` if `index` is out of bounds.
1495
+ /// Returns [ `None`] if `index` is out of bounds.
1467
1496
///
1468
1497
/// Element at index 0 is the front of the queue.
1469
1498
///
1499
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1500
+ ///
1470
1501
/// # Examples
1471
1502
///
1472
1503
/// ```
@@ -1709,7 +1740,9 @@ impl<T> VecDeque<T> {
1709
1740
///
1710
1741
/// # Panics
1711
1742
///
1712
- /// Panics if the new number of elements in self overflows a `usize`.
1743
+ /// Panics if the new number of elements in self overflows a [`usize`].
1744
+ ///
1745
+ /// [`usize`]: ../../std/primitive.usize.html
1713
1746
///
1714
1747
/// # Examples
1715
1748
///
0 commit comments