]> git.lizzy.rs Git - rust.git/commitdiff
Update splice impl
authorMatt Ickstadt <mattico8@gmail.com>
Sat, 8 Apr 2017 21:12:58 +0000 (16:12 -0500)
committerMatt Ickstadt <mattico8@gmail.com>
Mon, 24 Apr 2017 02:23:45 +0000 (21:23 -0500)
src/libcollections/string.rs
src/libcollections/vec.rs

index 8090bc1996e414a7cde696d419edf8612cdf9c3e..cc4f9b86be4d64b3ec9830d62638f3b65b9e4234 100644 (file)
@@ -1421,8 +1421,16 @@ pub fn splice<'a, 'b, R>(&'a mut self, range: R, replace_with: &'b str) -> Splic
         // Because the range removal happens in Drop, if the Splice iterator is leaked,
         // the removal will not happen.
         let len = self.len();
-        let start = *range.start().unwrap_or(&0);
-        let end = *range.end().unwrap_or(&len);
+        let start = match range.start() {
+             Included(&n) => n,
+             Excluded(&n) => n + 1,
+             Unbounded => 0,
+        };
+        let end = match range.end() {
+             Included(&n) => n + 1,
+             Excluded(&n) => n,
+             Unbounded => len,
+        };
 
         // Take out two simultaneous borrows. The &mut String won't be accessed
         // until iteration is over, in Drop.
@@ -2210,6 +2218,7 @@ impl<'a> FusedIterator for Drain<'a> {}
 ///
 /// [`splice()`]: struct.String.html#method.splice
 /// [`String`]: struct.String.html
+#[derive(Debug)]
 #[unstable(feature = "splice", reason = "recently added", issue = "32310")]
 pub struct Splice<'a, 'b> {
     /// Will be used as &'a mut String in the destructor
index bbb067ca4e3b6cf5898bf2d65e58d23c20caea27..dc330d4b2590b6cb56d11e396f1868084aae393f 100644 (file)
@@ -2394,7 +2394,14 @@ unsafe fn finalize(mut self) -> &'a mut T {
 }
 
 
-/// A splicing iterator for `Vec<T>`. See the [`Vec::splice`](struct.Vec.html#method.splice) method.
+/// A splicing iterator for `Vec`.
+///
+/// This struct is created by the [`splice()`] method on [`Vec`]. See its
+/// documentation for more.
+///
+/// [`splice()`]: struct.Vec.html#method.splice
+/// [`Vec`]: struct.Vec.html
+#[derive(Debug)]
 #[unstable(feature = "splice", reason = "recently added", issue = "32310")]
 pub struct Splice<'a, I: Iterator + 'a> {
     drain: Drain<'a, I::Item>,
@@ -2434,7 +2441,7 @@ fn drop(&mut self) {
 
         unsafe {
             if self.drain.tail_len == 0 {
-                let vec = &mut *self.drain.vec;
+                let vec = &mut *self.drain.vec.as_mut_ptr();
                 vec.extend(self.replace_with.by_ref());
                 return
             }
@@ -2476,7 +2483,7 @@ impl<'a, T> Drain<'a, T> {
     /// Fill that range as much as possible with new elements from the `replace_with` iterator.
     /// Return whether we filled the entire range. (`replace_with.next()` didn’t return `None`.)
     unsafe fn fill<I: Iterator<Item=T>>(&mut self, replace_with: &mut I) -> bool {
-        let vec = &mut *self.vec;
+        let vec = &mut *self.vec.as_mut_ptr();
         let range_start = vec.len;
         let range_end = self.tail_start;
         let range_slice = slice::from_raw_parts_mut(
@@ -2496,7 +2503,7 @@ unsafe fn fill<I: Iterator<Item=T>>(&mut self, replace_with: &mut I) -> bool {
 
     /// Make room for inserting more elements before the tail.
     unsafe fn move_tail(&mut self, extra_capacity: usize) {
-        let vec = &mut *self.vec;
+        let vec = &mut *self.vec.as_mut_ptr();
         let used_capacity = self.tail_start + self.tail_len;
         vec.buf.reserve(used_capacity, extra_capacity);