]> git.lizzy.rs Git - rust.git/commitdiff
Impls using the new scheme for slicing
authorNick Cameron <ncameron@mozilla.com>
Wed, 31 Dec 2014 07:20:40 +0000 (20:20 +1300)
committerNick Cameron <ncameron@mozilla.com>
Tue, 6 Jan 2015 21:24:19 +0000 (10:24 +1300)
src/libcollections/string.rs
src/libcollections/vec.rs
src/libcore/ops.rs
src/libcore/prelude.rs
src/libcore/slice.rs
src/libcore/str/mod.rs

index 0bf311e4d3f6e5674bc1eb9fd32f097087bea6e4..b05b5e276e8670d70a679de802a8799e3c6642a6 100644 (file)
@@ -818,25 +818,31 @@ fn add(mut self, other: &str) -> String {
     }
 }
 
-impl ops::Slice<uint, str> for String {
+impl<T> ops::Index<ops::Range<uint>, str> for String {
     #[inline]
-    fn as_slice_<'a>(&'a self) -> &'a str {
-        unsafe { mem::transmute(self.vec.as_slice()) }
+    fn index(&self, &index: &ops::Range<uint>) -> &str {
+        self[][*index]
     }
+}
 
+impl<T> ops::Index<ops::RangeTo<uint>, str> for String {
     #[inline]
-    fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
-        self[][*from..]
+    fn index(&self, &index: &ops::RangeTo<uint>) -> &str {
+        self[][*index]
     }
+}
 
+impl<T> ops::Index<ops::RangeFrom<uint>, str> for String {
     #[inline]
-    fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
-        self[][..*to]
+    fn index(&self, &index: &ops::RangeFrom<uint>) -> &str {
+        self[][*index]
     }
+}
 
+impl<T> ops::Index<ops::FullRange<uint>, str> for String {
     #[inline]
-    fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
-        self[][*from..*to]
+    fn index(&self, &index: &ops::FullRange<uint>) -> &str {
+        unsafe { mem::transmute(self.vec.as_slice()) }
     }
 }
 
index 99231e7253c3ce31f48baa0f8929ac9fdbcf156c..c057939df2b421e9fb6a92dc0613cb56c5e6258f 100644 (file)
@@ -1211,43 +1211,64 @@ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
 
 impl<T> ops::Slice<uint, [T]> for Vec<T> {
     #[inline]
-    fn as_slice_<'a>(&'a self) -> &'a [T] {
-        self.as_slice()
+    fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
+        &mut self.as_mut_slice()[*index]
     }
+}
 
+impl<T> ops::Index<ops::Range<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
-        self.as_slice().slice_from_or_fail(start)
+    fn index(&self, &index: &ops::Range<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
+}
 
+impl<T> ops::Index<ops::RangeTo<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
-        self.as_slice().slice_to_or_fail(end)
+    fn index(&self, &index: &ops::RangeTo<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
+}
+
+impl<T> ops::Index<ops::RangeFrom<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
-        self.as_slice().slice_or_fail(start, end)
+    fn index(&self, &index: &ops::RangeFrom<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
 }
 
-impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
+impl<T> ops::Index<ops::FullRange<uint>, [T]> for Vec<T> {
     #[inline]
-    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
-        self.as_mut_slice()
+    fn index(&self, &index: &ops::FullRange<uint>) -> &[T] {
+        self.as_slice()
     }
+}
 
+impl<T> ops::IndexMut<ops::Range<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
-        self.as_mut_slice().slice_from_or_fail_mut(start)
+    fn index_mut(&mut self, &index: &ops::Range<uint>) -> &mut [T] {
+        self.as_mut_slice().index_mut(index)
     }
+}
 
+impl<T> ops::IndexMut<ops::RangeTo<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
-        self.as_mut_slice().slice_to_or_fail_mut(end)
+    fn index_mut(&mut self, &index: &ops::RangeTo<uint>) -> &mut [T] {
+        self.as_mut_slice().index_mut(index)
     }
+}
+
+impl<T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for Vec<T> {
     #[inline]
-    fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
-        self.as_mut_slice().slice_or_fail_mut(start, end)
+    fn index_mut(&mut self, &index: &ops::RangeFrom<uint>) -> &mut [T] {
+        self.as_mut_slice().index_mut(index)
+    }
+}
+
+impl<T> ops::IndexMut<ops::FullRange<uint>, [T]> for Vec<T> {
+    #[inline]
+    fn index_mut(&mut self, &index: &ops::FullRange<uint>) -> &mut [T] {
+        self.as_mut_slice()
     }
 }
 
index 97d94e73bb33a0625764ba677ebdf97e49f8fe6f..2a7e6eb47955d2c642bbff73e181d2faac05ad8a 100644 (file)
@@ -846,105 +846,6 @@ pub trait IndexMut<Index: ?Sized> {
     fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
 }
 
-/// The `Slice` trait is used to specify the functionality of slicing operations
-/// like `arr[from..to]` when used in an immutable context.
-///
-/// # Example
-///
-/// A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up
-/// calling `slice_to`, and therefore, `main` prints `Slicing!`.
-///
-/// ```ignore
-/// use std::ops::Slice;
-///
-/// #[derive(Copy)]
-/// struct Foo;
-///
-/// impl Slice<Foo, Foo> for Foo {
-///     fn as_slice_<'a>(&'a self) -> &'a Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
-///         println!("Slicing!");
-///         self
-///     }
-/// }
-///
-/// fn main() {
-///     Foo[..Foo];
-/// }
-/// ```
-#[lang="slice"]
-pub trait Slice<Idx: ?Sized, Result: ?Sized> {
-    /// The method for the slicing operation foo[]
-    fn as_slice_<'a>(&'a self) -> &'a Result;
-    /// The method for the slicing operation foo[from..]
-    fn slice_from_or_fail<'a>(&'a self, from: &Idx) -> &'a Result;
-    /// The method for the slicing operation foo[..to]
-    fn slice_to_or_fail<'a>(&'a self, to: &Idx) -> &'a Result;
-    /// The method for the slicing operation foo[from..to]
-    fn slice_or_fail<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
-}
-
-/// The `SliceMut` trait is used to specify the functionality of slicing
-/// operations like `arr[from..to]`, when used in a mutable context.
-///
-/// # Example
-///
-/// A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up
-/// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`.
-///
-/// ```ignore
-/// use std::ops::SliceMut;
-///
-/// #[derive(Copy)]
-/// struct Foo;
-///
-/// impl SliceMut<Foo, Foo> for Foo {
-///     fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
-///         println!("Slicing!");
-///         self
-///     }
-///     fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
-///         println!("Slicing!");
-///         self
-///     }
-/// }
-///
-/// pub fn main() {
-///     Foo[mut Foo..];
-/// }
-/// ```
-#[lang="slice_mut"]
-pub trait SliceMut<Idx: ?Sized, Result: ?Sized> {
-    /// The method for the slicing operation foo[]
-    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Result;
-    /// The method for the slicing operation foo[from..]
-    fn slice_from_or_fail_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
-    /// The method for the slicing operation foo[..to]
-    fn slice_to_or_fail_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
-    /// The method for the slicing operation foo[from..to]
-    fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
-}
-
-
 /// An unbounded range.
 #[derive(Copy)]
 #[lang="full_range"]
@@ -962,8 +863,6 @@ pub struct Range<Idx> {
     pub end: Idx,
 }
 
-// FIXME(#19391) needs a snapshot
-//impl<Idx: Clone + Step<T=uint>> Iterator<Idx> for Range<Idx> {
 #[unstable = "API still in development"]
 impl<Idx: Clone + Step> Iterator for Range<Idx> {
     type Item = Idx;
index e88cb73c8a9b7f6f8d7b6f1a0a6c1207febc3f0d..a560b68db01fa89cf50098f2f9e5f1d4e792ea16 100644 (file)
@@ -30,7 +30,7 @@
 
 // Reexported core operators
 pub use kinds::{Copy, Send, Sized, Sync};
-pub use ops::{Drop, Fn, FnMut, FnOnce};
+pub use ops::{Drop, Fn, FnMut, FnOnce, FullRange};
 
 // Reexported functions
 pub use iter::range;
index 093ed0b242f5f4d5583f839a7534ee8e697d9912..369652b215f24b7acc4ed6b79ed4b9a9a378d96c 100644 (file)
@@ -292,17 +292,17 @@ fn get_mut(&mut self, index: uint) -> Option<&mut T> {
     fn as_mut_slice(&mut self) -> &mut [T] { self }
 
     fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
-        ops::SliceMut::slice_or_fail_mut(self, &start, &end)
+        ops::IndexMut::index_mut(self, &ops::Range { start: start, end: end } )
     }
 
     #[inline]
     fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
-        ops::SliceMut::slice_from_or_fail_mut(self, &start)
+        ops::IndexMut::index_mut(self, &ops::RangeFrom { start: start } )
     }
 
     #[inline]
     fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
-        ops::SliceMut::slice_to_or_fail_mut(self, &end)
+        ops::IndexMut::index_mut(self, &ops::RangeTo { end: end } )
     }
 
     #[inline]
@@ -310,8 +310,8 @@ fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
         unsafe {
             let self2: &mut [T] = mem::transmute_copy(&self);
 
-            (ops::SliceMut::slice_to_or_fail_mut(self, &mid),
-             ops::SliceMut::slice_from_or_fail_mut(self2, &mid))
+            (ops::IndexMut::index_mut(self, &ops::RangeTo { end: mid } ),
+             ops::IndexMut::index_mut(self2, &ops::RangeFrom { start: mid } ))
         }
     }
 
@@ -551,63 +551,78 @@ fn index_mut(&mut self, &index: &uint) -> &mut T {
     }
 }
 
-impl<T> ops::Slice<uint, [T]> for [T] {
+impl<T> ops::Index<ops::Range<uint>, [T]> for [T] {
     #[inline]
-    fn as_slice_<'a>(&'a self) -> &'a [T] {
-        self
+    fn index(&self, &index: &ops::Range<uint>) -> &[T] {
+        assert!(index.start <= index.end);
+        assert!(index.end <= self.len());
+        unsafe {
+            transmute(RawSlice {
+                    data: self.as_ptr().offset(index.start as int),
+                    len: index.end - index.start
+                })
+        }
+    }
+}
+
+impl<T> ops::Index<ops::RangeTo<uint>, [T]> for [T] {
+    #[inline]
+    fn index(&self, &index: &ops::RangeTo<uint>) -> &[T] {
+        self.index(&ops::Range{ start: 0, end: index.end })
     }
+}
 
+impl<T> ops::Index<ops::RangeFrom<uint>, [T]> for [T] {
     #[inline]
-    fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
-        self.slice_or_fail(start, &self.len())
+    fn index(&self, &index: &ops::RangeFrom<uint>) -> &[T] {
+        self.index(&ops::Range{ start: index.start, end: self.len() })
     }
+}
 
+impl<T> ops::Index<ops::FullRange, [T]> for [T] {
     #[inline]
-    fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
-        self.slice_or_fail(&0, end)
+    fn index(&self, &index: &ops::FullRange) -> &[T] {
+        self
     }
+}
+
+impl<T> ops::IndexMut<ops::Range<uint>, [T]> for [T] {
     #[inline]
-    fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
-        assert!(*start <= *end);
-        assert!(*end <= self.len());
+    fn index_mut(&mut self, &index: &ops::Range<uint>) -> &mut [T] {
+        assert!(index.start <= index.end);
+        assert!(index.end <= self.len());
         unsafe {
             transmute(RawSlice {
-                    data: self.as_ptr().offset(*start as int),
-                    len: (*end - *start)
+                    data: self.as_ptr().offset(index.start as int),
+                    len: index.end - index.start
                 })
         }
     }
 }
 
-impl<T> ops::SliceMut<uint, [T]> for [T] {
+impl<T> ops::IndexMut<ops::RangeTo<uint>, [T]> for [T] {
     #[inline]
-    fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
-        self
+    fn index_mut(&mut self, &index: &ops::RangeTo<uint>) -> &mut [T] {
+        self.index_mut(&ops::Range{ start: 0, end: index.end })
     }
+}
 
+impl<T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for [T] {
     #[inline]
-    fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
-        let len = &self.len();
-        self.slice_or_fail_mut(start, len)
+    fn index_mut(&mut self, &index: &ops::RangeFrom<uint>) -> &mut [T] {
+        let len = self.len();
+        self.index_mut(&ops::Range{ start: index.start, end: len })
     }
+}
 
+impl<T> ops::IndexMut<ops::FullRange, [T]> for [T] {
     #[inline]
-    fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
-        self.slice_or_fail_mut(&0, end)
-    }
-    #[inline]
-    fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
-        assert!(*start <= *end);
-        assert!(*end <= self.len());
-        unsafe {
-            transmute(RawSlice {
-                    data: self.as_ptr().offset(*start as int),
-                    len: (*end - *start)
-                })
-        }
+    fn index_mut(&mut self, &index: &ops::FullRange) -> &mut [T] {
+        self
     }
 }
 
+
 ////////////////////////////////////////////////////////////////////////////////
 // Common traits
 ////////////////////////////////////////////////////////////////////////////////
@@ -738,24 +753,38 @@ pub struct Iter<'a, T: 'a> {
 }
 
 #[experimental]
-impl<'a, T> ops::Slice<uint, [T]> for Iter<'a, T> {
-    fn as_slice_(&self) -> &[T] {
-        self.as_slice()
+impl<'a, T> ops::Index<ops::Range<uint>, [T]> for Iter<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::Range<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
-    fn slice_from_or_fail<'b>(&'b self, from: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice().slice_from_or_fail(from)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::RangeTo<uint>, [T]> for Iter<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
-    fn slice_to_or_fail<'b>(&'b self, to: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice().slice_to_or_fail(to)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::RangeFrom<uint>, [T]> for Iter<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
+        self.as_slice().index(index)
     }
-    fn slice_or_fail<'b>(&'b self, from: &uint, to: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice().slice_or_fail(from, to)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::FullRange, [T]> for Iter<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::FullRange) -> &[T] {
+        self.as_slice()
     }
 }
 
+
 impl<'a, T> Iter<'a, T> {
     /// View the underlying data as a subslice of the original data.
     ///
@@ -813,43 +842,70 @@ pub struct IterMut<'a, T: 'a> {
 }
 
 #[experimental]
-impl<'a, T> ops::Slice<uint, [T]> for IterMut<'a, T> {
-    fn as_slice_<'b>(&'b self) -> &'b [T] {
-        make_slice!(T -> &'b [T]: self.ptr, self.end)
+impl<'a, T> ops::Index<ops::Range<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::Range<uint>) -> &[T] {
+        self.index(&ops::FullRange).index(index)
     }
-    fn slice_from_or_fail<'b>(&'b self, from: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice_().slice_from_or_fail(from)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::RangeTo<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
+        self.index(&ops::FullRange).index(index)
     }
-    fn slice_to_or_fail<'b>(&'b self, to: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice_().slice_to_or_fail(to)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::RangeFrom<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
+        self.index(&ops::FullRange).index(index)
     }
-    fn slice_or_fail<'b>(&'b self, from: &uint, to: &uint) -> &'b [T] {
-        use ops::Slice;
-        self.as_slice_().slice_or_fail(from, to)
+}
+
+#[experimental]
+impl<'a, T> ops::Index<ops::FullRange, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index(&self, index: &ops::FullRange) -> &[T] {
+        make_slice!(T -> &[T]: self.ptr, self.end)
     }
 }
 
 #[experimental]
-impl<'a, T> ops::SliceMut<uint, [T]> for IterMut<'a, T> {
-    fn as_mut_slice_<'b>(&'b mut self) -> &'b mut [T] {
-        make_slice!(T -> &'b mut [T]: self.ptr, self.end)
+impl<'a, T> ops::IndexMut<ops::Range<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
+        self.index_mut(&ops::FullRange).index_mut(index)
     }
-    fn slice_from_or_fail_mut<'b>(&'b mut self, from: &uint) -> &'b mut [T] {
-        use ops::SliceMut;
-        self.as_mut_slice_().slice_from_or_fail_mut(from)
+}
+
+#[experimental]
+impl<'a, T> ops::IndexMut<ops::RangeTo<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
+        self.index_mut(&ops::FullRange).index_mut(index)
     }
-    fn slice_to_or_fail_mut<'b>(&'b mut self, to: &uint) -> &'b mut [T] {
-        use ops::SliceMut;
-        self.as_mut_slice_().slice_to_or_fail_mut(to)
+}
+
+#[experimental]
+impl<'a, T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
+        self.index_mut(&ops::FullRange).index_mut(index)
     }
-    fn slice_or_fail_mut<'b>(&'b mut self, from: &uint, to: &uint) -> &'b mut [T] {
-        use ops::SliceMut;
-        self.as_mut_slice_().slice_or_fail_mut(from, to)
+}
+
+#[experimental]
+impl<'a, T> ops::IndexMut<ops::FullRange, [T]> for IterMut<'a, T> {
+    #[inline]
+    fn index_mut(&mut self, index: &ops::FullRange) -> &mut [T] {
+        make_slice!(T -> &mut [T]: self.ptr, self.end)
     }
 }
 
+
 impl<'a, T> IterMut<'a, T> {
     /// View the underlying data as a subslice of the original data.
     ///
index a39787b8207b5161c2fcbdb54c899d0829a93e11..a28e56144177ed417fd3746e21a6f2a915587d46 100644 (file)
@@ -1119,25 +1119,31 @@ fn partial_cmp(&self, other: &str) -> Option<Ordering> {
         }
     }
 
-    impl ops::Slice<uint, str> for str {
+    impl ops::Index<ops::Range<uint>, str> for str {
         #[inline]
-        fn as_slice_<'a>(&'a self) -> &'a str {
-            self
+        fn index(&self, &index: &ops::Range<uint>) -> &str {
+            self.slice(index.start, index.end)
         }
+    }
 
+    impl ops::Index<ops::RangeTo<uint>, str> for str {
         #[inline]
-        fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str {
-            self.slice_from(*from)
+        fn index(&self, &index: &ops::RangeTo<uint>) -> &str {
+            self.slice_to(index.end)
         }
+    }
 
+    impl ops::Index<ops::RangeFrom<uint>, str> for str {
         #[inline]
-        fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str {
-            self.slice_to(*to)
+        fn index(&self, &index: &ops::RangeFrom<uint>) -> &str {
+            self.slice_from(index.start)
         }
+    }
 
+    impl ops::Index<ops::FullRange, str> for str {
         #[inline]
-        fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
-            self.slice(*from, *to)
+        fn index(&self, &index: &ops::FullRange) -> &str {
+            self
         }
     }
 }