Skip to content

Commit 17d23b8

Browse files
committed
vec: make unsafe indexing functions higher-level
1 parent 802d41f commit 17d23b8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/libstd/vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ pub trait ImmutableVector<'a, T> {
960960
fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U];
961961
/// Returns a pointer to the element at the given index, without doing
962962
/// bounds checking.
963-
unsafe fn unsafe_ref(&self, index: uint) -> *T;
963+
unsafe fn unsafe_ref(self, index: uint) -> &'a T;
964964

965965
/**
966966
* Returns an unsafe pointer to the vector's buffer
@@ -1149,8 +1149,8 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
11491149
}
11501150

11511151
#[inline]
1152-
unsafe fn unsafe_ref(&self, index: uint) -> *T {
1153-
self.repr().data.offset(index as int)
1152+
unsafe fn unsafe_ref(self, index: uint) -> &'a T {
1153+
cast::transmute(self.repr().data.offset(index as int))
11541154
}
11551155

11561156
#[inline]
@@ -2183,7 +2183,7 @@ pub trait MutableVector<'a, T> {
21832183
fn move_from(self, src: ~[T], start: uint, end: uint) -> uint;
21842184

21852185
/// Returns an unsafe mutable pointer to the element in index
2186-
unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T;
2186+
unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T;
21872187

21882188
/// Return an unsafe mutable pointer to the vector's buffer.
21892189
///
@@ -2361,8 +2361,8 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
23612361
}
23622362

23632363
#[inline]
2364-
unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T {
2365-
ptr::mut_offset(self.repr().data as *mut T, index as int)
2364+
unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T {
2365+
cast::transmute(ptr::mut_offset(self.repr().data as *mut T, index as int))
23662366
}
23672367

23682368
#[inline]

0 commit comments

Comments
 (0)