diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-01-21 09:34:42 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-01-22 23:13:57 -0500 |
| commit | 17d23b8c1727d5fc6fa696d931caf87fa8c0809b (patch) | |
| tree | fd274d0b44821bcb5665a0fa160f205290f91cb4 /src/libstd/vec.rs | |
| parent | 802d41fe235794d84084897ae6187ee5cc27dd95 (diff) | |
| download | rust-17d23b8c1727d5fc6fa696d931caf87fa8c0809b.tar.gz rust-17d23b8c1727d5fc6fa696d931caf87fa8c0809b.zip | |
vec: make unsafe indexing functions higher-level
Diffstat (limited to 'src/libstd/vec.rs')
| -rw-r--r-- | src/libstd/vec.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 885c669ecb4..8e8e5f6e62c 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -960,7 +960,7 @@ pub trait ImmutableVector<'a, T> { fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U]; /// Returns a pointer to the element at the given index, without doing /// bounds checking. - unsafe fn unsafe_ref(&self, index: uint) -> *T; + unsafe fn unsafe_ref(self, index: uint) -> &'a T; /** * Returns an unsafe pointer to the vector's buffer @@ -1149,8 +1149,8 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { } #[inline] - unsafe fn unsafe_ref(&self, index: uint) -> *T { - self.repr().data.offset(index as int) + unsafe fn unsafe_ref(self, index: uint) -> &'a T { + cast::transmute(self.repr().data.offset(index as int)) } #[inline] @@ -2183,7 +2183,7 @@ pub trait MutableVector<'a, T> { fn move_from(self, src: ~[T], start: uint, end: uint) -> uint; /// Returns an unsafe mutable pointer to the element in index - unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T; + unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T; /// Return an unsafe mutable pointer to the vector's buffer. /// @@ -2361,8 +2361,8 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { } #[inline] - unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T { - ptr::mut_offset(self.repr().data as *mut T, index as int) + unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T { + cast::transmute(ptr::mut_offset(self.repr().data as *mut T, index as int)) } #[inline] |
