Skip to content

Commit a073100

Browse files
author
jonastepe
committed
len needs to be prefixed by self for this to work. The final code in this section of the book is correct.
1 parent 2edb1d9 commit a073100

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/doc/nomicon/vec-insert-remove.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn insert(&mut self, index: usize, elem: T) {
2424
// ptr::copy(src, dest, len): "copy from source to dest len elems"
2525
ptr::copy(self.ptr.offset(index as isize),
2626
self.ptr.offset(index as isize + 1),
27-
len - index);
27+
self.len - index);
2828
}
2929
ptr::write(self.ptr.offset(index as isize), elem);
3030
self.len += 1;
@@ -44,7 +44,7 @@ pub fn remove(&mut self, index: usize) -> T {
4444
let result = ptr::read(self.ptr.offset(index as isize));
4545
ptr::copy(self.ptr.offset(index as isize + 1),
4646
self.ptr.offset(index as isize),
47-
len - index);
47+
self.len - index);
4848
result
4949
}
5050
}

0 commit comments

Comments
 (0)