about summary refs log tree commit diff
path: root/src/libcore/slice.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/slice.rs')
-rw-r--r--src/libcore/slice.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index eaa52c99c4a..138422ceff1 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -256,7 +256,6 @@ pub trait SlicePrelude<T> for Sized? {
     #[inline]
     #[experimental = "not triaged yet"]
     fn is_empty(&self) -> bool { self.len() == 0 }
-
     /// Returns a mutable reference to the element at the given index,
     /// or `None` if the index is out of bounds
     #[unstable = "waiting on final error conventions"]
@@ -698,6 +697,22 @@ impl<T> SlicePrelude<T> for [T] {
     }
 }
 
+impl<T> ops::Index<uint, T> for [T] {
+    fn index(&self, &index: &uint) -> &T {
+        assert!(index < self.len());
+
+        unsafe { mem::transmute(self.repr().data.offset(index as int)) }
+    }
+}
+
+impl<T> ops::IndexMut<uint, T> for [T] {
+    fn index_mut(&mut self, &index: &uint) -> &mut T {
+        assert!(index < self.len());
+
+        unsafe { mem::transmute(self.repr().data.offset(index as int)) }
+    }
+}
+
 impl<T> ops::Slice<uint, [T]> for [T] {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a [T] {