1
+ #![ warn( rust_2018_idioms) ]
2
+ #![ allow( elided_lifetimes_in_paths) ]
1
3
#![ allow( dead_code) ]
2
4
3
5
mod gap {
4
- use std;
5
6
use std:: ops:: Range ;
6
7
7
8
/// A GapBuffer<T> is a sequence of elements of type `T` that can insert and
@@ -42,24 +43,24 @@ mod gap {
42
43
}
43
44
44
45
/// Return a pointer to the `index`'th element of the underlying storage,
45
- /// as if the gap were not there .
46
+ /// regardless of the gap.
46
47
///
47
- /// Safety: `index` must be less than self.capacity() .
48
+ /// Safety: `index` must be a valid index into ` self.storage` .
48
49
unsafe fn space ( & self , index : usize ) -> * const T {
49
50
self . storage . as_ptr ( ) . offset ( index as isize )
50
51
}
51
52
52
53
/// Return a mutable pointer to the `index`'th element of the underlying
53
- /// storage, as if the gap were not there .
54
+ /// storage, regardless of the gap.
54
55
///
55
- /// Safety: `index` must be less than self.capacity() .
56
+ /// Safety: `index` must be a valid index into ` self.storage` .
56
57
unsafe fn space_mut ( & mut self , index : usize ) -> * mut T {
57
58
self . storage . as_mut_ptr ( ) . offset ( index as isize )
58
59
}
59
60
60
61
/// Return the offset in the buffer of the `index`'th element, taking
61
62
/// the gap into account. This does not check whether index is in range,
62
- /// but it never returns the index of space in the gap.
63
+ /// but it never returns an index in the gap.
63
64
fn index_to_raw ( & self , index : usize ) -> usize {
64
65
if index < self . gap . start {
65
66
index
@@ -193,18 +194,18 @@ mod gap {
193
194
std:: ptr:: drop_in_place ( self . space_mut ( i) ) ;
194
195
}
195
196
for i in self . gap . end .. self . capacity ( ) {
196
- drop ( std:: ptr:: read ( self . space ( i ) ) ) ;
197
+ std:: ptr:: drop_in_place ( self . space_mut ( i ) ) ;
197
198
}
198
199
}
199
200
}
200
201
}
201
202
202
- pub struct Iter < ' a , T : ' a > {
203
+ pub struct Iter < ' a , T > {
203
204
buffer : & ' a GapBuffer < T > ,
204
205
pos : usize
205
206
}
206
207
207
- impl < ' a , T : ' a > Iterator for Iter < ' a , T > {
208
+ impl < ' a , T > Iterator for Iter < ' a , T > {
208
209
type Item = & ' a T ;
209
210
fn next ( & mut self ) -> Option < & ' a T > {
210
211
if self . pos >= self . buffer . len ( ) {
@@ -246,7 +247,7 @@ mod gap {
246
247
mod gap_tests {
247
248
#[ test]
248
249
fn test ( ) {
249
- use gap:: GapBuffer ;
250
+ use super :: gap:: GapBuffer ;
250
251
251
252
let mut buf = GapBuffer :: new ( ) ;
252
253
buf. insert_iter ( "Lord of the Rings" . chars ( ) ) ;
@@ -259,7 +260,7 @@ mod gap_tests {
259
260
260
261
#[ test]
261
262
fn misc ( ) {
262
- use gap:: GapBuffer ;
263
+ use super :: gap:: GapBuffer ;
263
264
264
265
let mut gb = GapBuffer :: new ( ) ;
265
266
println ! ( "{:?}" , gb) ;
@@ -301,7 +302,7 @@ mod gap_tests {
301
302
302
303
#[ test]
303
304
fn drop_elements ( ) {
304
- use gap:: GapBuffer ;
305
+ use super :: gap:: GapBuffer ;
305
306
306
307
let mut gb = GapBuffer :: new ( ) ;
307
308
gb. insert ( "foo" . to_string ( ) ) ;
0 commit comments