Skip to content

Commit be52700

Browse files
committed
gap-buffer: Update for Rust 2018.
1 parent bdd1751 commit be52700

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

gap-buffer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
name = "gap-buffer"
33
version = "0.1.0"
44
authors = ["You <[email protected]>"]
5+
edition = "2018"
56

67
[dependencies]

gap-buffer/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#![warn(rust_2018_idioms)]
2+
#![allow(elided_lifetimes_in_paths)]
13
#![allow(dead_code)]
24

35
mod gap {
4-
use std;
56
use std::ops::Range;
67

78
/// A GapBuffer<T> is a sequence of elements of type `T` that can insert and
@@ -42,24 +43,24 @@ mod gap {
4243
}
4344

4445
/// 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.
4647
///
47-
/// Safety: `index` must be less than self.capacity().
48+
/// Safety: `index` must be a valid index into `self.storage`.
4849
unsafe fn space(&self, index: usize) -> *const T {
4950
self.storage.as_ptr().offset(index as isize)
5051
}
5152

5253
/// 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.
5455
///
55-
/// Safety: `index` must be less than self.capacity().
56+
/// Safety: `index` must be a valid index into `self.storage`.
5657
unsafe fn space_mut(&mut self, index: usize) -> *mut T {
5758
self.storage.as_mut_ptr().offset(index as isize)
5859
}
5960

6061
/// Return the offset in the buffer of the `index`'th element, taking
6162
/// 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.
6364
fn index_to_raw(&self, index: usize) -> usize {
6465
if index < self.gap.start {
6566
index
@@ -193,18 +194,18 @@ mod gap {
193194
std::ptr::drop_in_place(self.space_mut(i));
194195
}
195196
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));
197198
}
198199
}
199200
}
200201
}
201202

202-
pub struct Iter<'a, T: 'a> {
203+
pub struct Iter<'a, T> {
203204
buffer: &'a GapBuffer<T>,
204205
pos: usize
205206
}
206207

207-
impl<'a, T: 'a> Iterator for Iter<'a, T> {
208+
impl<'a, T> Iterator for Iter<'a, T> {
208209
type Item = &'a T;
209210
fn next(&mut self) -> Option<&'a T> {
210211
if self.pos >= self.buffer.len() {
@@ -246,7 +247,7 @@ mod gap {
246247
mod gap_tests {
247248
#[test]
248249
fn test() {
249-
use gap::GapBuffer;
250+
use super::gap::GapBuffer;
250251

251252
let mut buf = GapBuffer::new();
252253
buf.insert_iter("Lord of the Rings".chars());
@@ -259,7 +260,7 @@ mod gap_tests {
259260

260261
#[test]
261262
fn misc() {
262-
use gap::GapBuffer;
263+
use super::gap::GapBuffer;
263264

264265
let mut gb = GapBuffer::new();
265266
println!("{:?}", gb);
@@ -301,7 +302,7 @@ mod gap_tests {
301302

302303
#[test]
303304
fn drop_elements() {
304-
use gap::GapBuffer;
305+
use super::gap::GapBuffer;
305306

306307
let mut gb = GapBuffer::new();
307308
gb.insert("foo".to_string());

0 commit comments

Comments
 (0)